use strict; use Benchmark; for ( 1..5 ) # Do five tests. { $_ = int( rand(10_000) ) ** int( rand(3) + 2 ); $_ = "For $_ Merlyn " . reverse($_) . " plus the constants ". "8634641234541275032000523 and 8,634,641,234,541,275,032,000,523"; print $_, "\n"; timethese( 1_000_000, { 'KM' => sub { 1 while s/^(-?\d+)(\d{3})/$1,$2/ }, 'Merlyn' => sub {s/(\d)(?=(\d{3})+(\D|$))/$1\,/g} }); print "\n", "- " x 39, "-\n"; }