You'd need to use cmp instead of <=> for the parts of the split that you want sorted alphabetically:
{(my $a1, $a2) = split(/~/, $a); (my $b1, $b2) = split(/~/, $b); $a1 <=> $b1 || $a2 cmp $b2}
That code is pretty cool. <=> and cmp evaluate to 0 when the values are equal, so the second...