foreach my $z (0 .. ($#arr-1)) { my @arr_sorted = sort{???} @arr; }