in reply to Sorting a two-dimensional array by two columns

I'm not sure why you're building up @chrnums and @coords and then taking a slice of @twodarray. You should be able to do everything in 1 step with something like:
my @data = ( [ 'chr1', 10 ], [ 'chr1', 30 ], [ 'chr1', 20 ], [ 'chr3', 11 ], [ 'chr3', 40 ], [ 'chr2', 10 ], [ 'chr3', 10 ], [ 'chr2', 40 ], [ 'chr3', 20 ], [ 'chr2', 20 ], ); my @sorted = sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] } @data ;