Pass user-defined function to sort function
@array = (6, 5, 4, 3, 2, 1); sub myfunction { return (shift(@_) <=> shift(@_)); } print join(", ", sort {myfunction($a, $b)} @array);