use Benchmark; timethese(1000000, { 'regexp' => sub { my($file) = $img =~ m#.*/(.*)# }, 'substr' => sub { my $file = substr $img, rindex($img, '/') + 1 } });