in reply to sorting multidimensional arrays

It's convenient to mirror the array (switch rows for columns), sort it, then mirror it back.

use strict; use warnings; sub mirror { my $num_rows = @_; my $num_cols = @{$_[0]}; return ( map { my $col = $_; [ map { my $row = $_; $_[$row][$col] } 0..$num_rows-1 ] } 0..$num_cols-1 ); } my @unsorted_array = ([8,9,10], [6,5,4], [7,8,9]); my @sorted_array = mirror sort { $a->[1] <=> $b->[1] } mirror @unsorted_array; require Data::Dumper; print(Data::Dumper::Dumper(\@sorted_array)); __END__ Original ======== [ 8, 9, 10 ] [ 6, 5, 4 ] [ 7, 8, 9 ] After Bottom Mirror =================== [ 8, 6, 7 ] [ 9, 5, 8 ] [ 10, 4, 9 ] After Sort ========== [ 10, 4, 9 ] [ 9, 5, 8 ] [ 8, 6, 7 ] After Top Mirror ================ [ 10, 9, 8 ] [ 4, 5, 6 ] [ 9, 8, 7 ]