Help for this page

Select Code to Download


  1. or download this
    use Benchmark 'cmpthese';
    use strict;
    ...
    print "Keep: ", join("\n", @copy), "\n";
    two;
    print "Two: ", join("\n", @copy), "\n";
    
  2. or download this
              Rate replace    keep     two
    replace 4739/s      --    -15%    -26%
    ...
    Two: one two  four
    two  four five
    one three five
    
  3. 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 }
    
  4. or download this
    sub two     { /o+ (?=(three))/g and substr($_, $-[1], $+[1]-$-[1], '')
    + for @copy=@strings