in reply to sort messes up data

I think you're confused about the contents of @List.

The elements of @List are not indices but references. But in your sort block, you treat them as indices, which Perl will happily do, but which will not yield the result you want. A reference when used as number evaluates roughly to the memory address where the data is stored. Your array indices are not that.

Maybe you want to use real array indices, or the array elements themselves?

# Sort by using indices @SortedList = sort { $List[$a][0] <=> $List[$b][0] } 0..$#List; # Sort by using array elements @SortedList = sort { $a->[0] <=> $b->[0] } @List;