$s = join'', map{ chr( 65+rand(26) ) x rand( 100 ) } 1 .. 1000;; cmpthese( -1,{ a=>q[ 1 while $s =~ m[((?=(.))\2+)]g; ], b=>q[ 1 while $s =~ m[((?=(.))\2+)]sg; ] , c=>q[ 1 while $s =~ m/((.)\2*)/sg; ], d=>q[ 1 while $s =~ m{ ( (?=(.)) (?: (\2\2\2\2\2\2\2\2) \3* | (\2\2\2\2) \4* | (\2\2) \5* | \2+ )+ ) }sgx; ], }); Rate b a c d b 193/s -- -0% -3% -35% a 194/s 0% -- -2% -35% c 198/s 3% 2% -- -33% d 296/s 54% 53% 50% --