sub dumpit { my $out; # Redirect STDOUT to a string open my $oldout, ">&STDOUT" or warn "Can't dup STDOUT: $!"; close STDOUT; open(STDOUT,'>',\$out) or warn "STDOUT redirection failed:$!"; B::Showlex::compile(-newlex,-nosp,'mysub')->(); my @lines = split(/\n/,$out); shift @lines; shift @lines; for my $line (@lines) { $line =~ s/.*\"(.\w+)\".*/$1/; print STDERR "$line\n"; } # Restore STDOUT open STDOUT, ">&", $oldout or die "Can't dup \$oldout: $!"; }