#!/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; }, } ); }