my @sorted = sort { $hash{$b} <=> $hash{$a} || $a cmp $b || func($a) <=> func($b) || $other{name}{$b} cmp $other{name}{$a} } @unsorted;