use strict; use warnings; use Benchmark 'cmpthese'; my $str = ' ' x 1e5; sub test1 { my $s = shift; my $copy = substr $str, 1; 1 while $copy =~ /./g; _: } sub test2 { my $s = shift; substr $s, 0, 1, ''; 1 while $s =~ /./g; _: } cmpthese -1, { test1 => sub { test1( $str )}, test2 => sub { test2( $str )}, }; # (warning: too few iterations for a reliable count) # Rate test2 test1 # test2 2.79/s -- -93% # test1 41.0/s 1372% --