$ perl testLocal.pl Benchmark: running localWhile, localWhileQR, whileLocal, each for at least 3 CPU seconds... localWhile: 4 wallclock secs ( 3.02 usr + 0.00 sys = 0.02 CPU) @ 28894.20/s (n=87116) localWhileQR: 4 wallclock secs ( 3.17 usr + 0.01 sys = 3.18 CPU) @ 45765.70/s (n=145718) whileLocal: 4 wallclock secs ( 3.09 usr + 0.00 sys = 3.09 CPU) @ 20884.62/s (n=64617) Rate whileLocal localWhile localWhileQR whileLocal 20885/s -- -28% -54% localWhile 28894/s 38% -- -37% localWhileQR 45766/s 119% 58% -- #### $ cat testLocal.pl #!/usr/bin/perl -w use strict; use Benchmark qw(cmpthese); my @a=qw(a x z); # if you increase the number of test strings, the differences # get even more pronounced... my @strings=qw(a x z vvvvv vvvvva vvvvvb vvvvvx vvvvvz aaa axz azz axx); sub localWhile{ local $"=""; my $count; foreach(@strings) { $count++ if /^[@a]{3}$/; } die unless $count==4; } sub whileLocal{ my $count; foreach(@strings) { local $"=""; $count++ if /^[@a]{3}$/; } die unless $count==4; } sub localWhileQR{ my $count; local $"=""; my $re=qr/^[@a]{3}$/; foreach(@strings) { $count++ if /$re/; } die unless $count==4; } cmpthese(-3, { localWhile => \&localWhile, localWhileQR => \&localWhileQR, whileLocal => \&whileLocal } );