in reply to Regular expressions and sort

You should always, always either combine capturing patterns with conditionals or use list assignment to pull out captures.

In your case, that means I’d write the routine in either of these ways:

sub sorter ($$) { my $am = ( $_[0] =~ /$mask/ ) ? $1 : ''; my $bm = ( $_[1] =~ /$mask/ ) ? $1 : ''; $am <=> $bm || $am cmp $bm; } # or sub sorter ($$) { my ( $am ) = ( $_[0] =~ /$mask/ ); my ( $bm ) = ( $_[1] =~ /$mask/ ); $am <=> $bm || $am cmp $bm; } # note: these are not quite equivalent # after a failed match, $am and $bm will contain: # #1) an empty string # #2) undef

Never use $1 when you’re not checking for a pattern match’s success.

Makeshifts last the longest.