@sorted = sort {&foo($orig[$a]) cmp &foo($orig[$b]) || $a <=> $b} (0 .. @orig - 1)