#! perl -slw use strict; use Benchmark qw[ cmpthese ]; sub rndStr{ join'', map{ $_[ rand scalar @_ ] } 0 .. shift } our @strings = map{ rndStr 8, ':', 'a' .. 'z' } 1 .. 1000; our( @a, @b, @c, @d ); cmpthese( -3, { regex => q[ our @a = sort{ ( $a =~ /:/ <=> $b =~ /:/ ) || $a cmp $b } @strings ], index => q[ our @b = sort{ ( ( index($a,':') >= 0 ) <=> ( index($b,':') >= 0) ) || $a cmp $b; } @strings ], Abi_regex => q[ @c = map{ substr $_ => 1 } sort map{ /:/ ? "0$_" : "1$_" } @strings ], Abi_index => q[ @c = map{ substr $_ => 1 } sort map{ 1+index($_, ':') ? "0$_" : "1$_" } @strings ], }); print 'Okay' if "@a" eq "@b" or "@b" ne "@c" or "@c" ne "@d"; __END__ P:\test>test3 Rate regex index Abi_regex Abi_index regex 13.9/s -- -14% -21% -27% index 16.3/s 17% -- -7% -15% Abi_regex 17.6/s 26% 8% -- -9% Abi_index 19.2/s 38% 18% 9% -- Okay