use strict; use warnings; use Benchmark qw(:all); my $string="He0Hello~~He2World~~"; sub invertedCharclass { $string=~m/He\d([^~]+)~~/g } sub nonGreedy { $string=~m/He\d(.+?)~~/g } cmpthese (-10, { '[^~]+' => \&invertedCharclass, '.+?' => \&nonGreedy, } ); #### Rate [^~]+ .+? [^~]+ 236537/s -- -22% .+? 303038/s 28% --