my @index_sorted = map { my @row = splice @sim, 0, N; sort { $row[$b] <=> $row[$a] } 0..(N-1); } 0..(M-1);