A great module for this is Devel::DumpTrace.
An alternative to Devel::DumpTrace:
Step 1) Add this code anywhere in your main Perl script:
END { # Whenever this script shuts down, record a list of all Perl code files that # were used while it was running. use Cwd 'abs_path'; my $logfile = abs_path($0); $logfile =~ s#/#_#g; $logfile = "/tmp/Perl_files$logfile." . getpwuid( $< ) . ".txt"; if (open my $f, '>', $logfile) { print $f join("\n", sort values %INC, abs_path($0)), "\n"; print "Perl file list output to file $logfile\n" if (-t STDOUT); } }
Step 2) Run your script, and afterwards there should be a file generated named something like /tmp/Perl_files...$USER.txt
.
Step 3) If you want to search for a subroutine or variable within that list of files:
$ grep 'regex' $(cat /tmp/Perl_files_blahblah.root.txt)
This works for CGI scripts too, though in that case, you might have to try to guess the name of the file that was written: ls -lrt /tmp/Perl_files_*