There is an easy way to measure the performance of every part of your Perl code – it’s called NYTProf.
If you don’t have it yet, install the profiling modul Devel::YTProf
sudo perl -MCPAN -e 'install Devel::NYTProf'
Then run your Perl script with an additional call to the profiler:
perl -d:NYTProf script.pl input.file
The -d starts the debug mode which is a short hand for -MDevel:: (loads the module Devel::NYTProf before running your Perl script).
The profiler produces the file nytprof.out. Please note that the profiler will add some addtional processing time to your script.
The last step is to generate the HTML output that will show you all the results of the profiler (including the time spend on each line of code used while running the script).
nytprofhtml -o nytprof -f nytprof.out
The -o defines the output directory where all the HTML files will be written to and the -f defines the input file name (useful if you want to compare multiple runs, otherwise it can be ignored as it defaults to nytprof.out).
Now open the index.html in the output directory and start improving your code!