- or download this
use Benchmark 'cmpthese';
use strict;
...
print "Keep: ", join("\n", @copy), "\n";
two;
print "Two: ", join("\n", @copy), "\n";
- or download this
Rate replace keep two
replace 4739/s -- -15% -26%
...
Two: one two four
two four five
one three five
- or download this
sub replace { s/(o+ )three/$1/g for @copy=@strings }
sub keep { s/o+ \Kthree//g for @copy=@strings }
sub two { do {s/\Gthree// while /o+ /g} for @copy=@strings }
- or download this
sub two { /o+ (?=(three))/g and substr($_, $-[1], $+[1]-$-[1], '')
+ for @copy=@strings