use strict; use Benchmark qw/timethese cmpthese/; # use re 'debug'; chomp(my @lines = ); my $target = shift || 'word'; my $re_positive_lookahead = qr/^a=<(?=.*?word)/; my $re_loose = qr/a=<(.*?$target.*?)>/; cmpthese( timethese(1000000, { 'Match_L' => '&Match_Loose', 'Match_P' => '&Match_PLAhead_plus_Substr', }) ); sub Match_Loose { foreach (@lines) { if (/$re_loose/) { my $word = $1; } } } sub Match_PLAhead_plus_Substr { foreach (@lines) { if (/$re_positive_lookahead/) { my $word = substr($_, 3, length($_)-4); } } } __DATA__ a= a= b= a= b= a= b= a= b= b= b= #### Benchmark: timing 1000000 iterations of Match_L, Match_P... Match_L: 31 wclock secs (31.16 usr + 0.00 sys = 31.16 CPU) @ 32092.43/s Match_P: 27 wclock secs (27.64 usr + 0.00 sys = 27.64 CPU) @ 36179.45/s Rate Match_L Match_P Match_L 32092/s -- -11% Match_P 36179/s 13% --