#!/usr/bin/perl use strict; use warnings; no warnings "numeric" ; use Benchmark "cmpthese"; my %strings = ( '999:1' => scalar ('"' x 999 . '-') x 1000, '9:1' => '"""""""""-' x 100000, '1:1' => '"-' x 500000, ); for my $test (sort {$b<=>$a} keys %strings) { my $s = $strings{$test}; printf "\n%s... ($test):\n\n", substr($s,0,30); cmpthese (1000, { 's/"//g' => sub { my $t = $s; $t =~ s/"//g; }, 's/"+//g' => sub { my $t = $s; $t =~ s/"+//g; }, 'tr/"//d' => sub { my $t = $s; $t =~ tr/"//d; }, } ); } #### $ ./700801.pl """"""""""""""""""""""""""""""... (999:1): Rate s/"//g tr/"//d s/"+//g s/"//g 4.09/s -- -98% -99% tr/"//d 212/s 5079% -- -31% s/"+//g 309/s 7445% 46% -- """""""""-"""""""""-"""""""""-... (9:1): Rate s/"//g s/"+//g tr/"//d s/"//g 4.49/s -- -85% -98% s/"+//g 30.7/s 584% -- -83% tr/"//d 181/s 3931% 490% -- "-"-"-"-"-"-"-"-"-"-"-"-"-"-"-... (1:1): Rate s/"+//g s/"//g tr/"//d s/"+//g 6.78/s -- -16% -97% s/"//g 8.05/s 19% -- -96% tr/"//d 211/s 3005% 2515% --