It looks like you want to sort by one key first, and if this key is the same, then you want to sort the second key.
eg. you want 45 + 2 to be sorted between 45 and 46.
You can do this simply by using:
@ls = sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @ls
Only if the first key is the same, consult the second key.
Here is a complete example:
my @allinfogoals=( [ 46, 0 ], [ 45, 2 ], [ 45, 0 ], [ 33, 0 ], [ 91, 0 ], [ 90, 2 ], ); @allinfogoals=sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @allinfogoals; use Data::Dump; dd \@allinfogoals;
And the result:
[[33, 0], [45, 0], [45, 2], [46, 0], [90, 2], [91, 0]]