use strict; use Benchmark qw< cmpthese >; my $doc = ' "a string",' x 1_024_000; cmpthese( -1, { copy => sub { return $1 if $doc =~ /(['"])/; }, substr => sub { return substr( $doc, pos($doc)-1, 1 ) if $doc =~ /['"]/g; }, } ); __END__ Rate copy substr copy 38.6/s -- -100% substr 382480/s 991549% --