$ 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 } );