# sort things containing a colon after things without # fist attempt if ( $a =~ /:/ ){ return $a cmp $b if $b =~ /:/; return 1; } if ( $b =~ /:/ ){ return -1; } $a cmp $b; # version 2, only one $a cmp $b return 1 if ( $a =~ /:/ and $b !~ /:/ ); return -1 if ( $b =~ /:/ and $a !~ /:/ ); $a cmp $b; # version 3 with input from a colleague, only apply a re to # each var once now if ( my $x = ($a =~ /:/) <=> ($b =~ /:/) ){ return $x; } $a cmp $b; # maybe better maybe not but it allowed me to see the # final option- my $x = ($a =~ /:/) <=> ($b =~ /:/); $x ? $x : $a cmp $b; # a good nights sleep and... (($a =~ /:/) <=> ($b =~ /:/)) || $a cmp $b;