use Data::Dumper; $a=[1,[2,3],4]; $d=Dumper($a); $d =~ s/.*=//; $d =~ /^\s*\[\n(\s*)1,\n((?:.*\n)*?\1[^\s].*?,)/m and print eval ($2)->[1];