use Benchmark; # at the beginning: my $benchmarkStart = Benchmark->new(); # code to benchmark # at the end: my $benchmarkEnd = Benchmark->new(); my $diff = Benchmark::timediff($benchmarkEnd, $benchmarkStart); my $str = Benchmark::timestr($diff); if ($str =~ /(\d+)\s*wallclock secs \(\s*?(\d*?\.\d*?)\s*usr\s*\+\s*(\d*?\.\d*?)\s/i) { printf ("Execution time: ~ %.0f seconds\nCPU-Time : %.2f\n", $1, $2); }