@sortedarry = map { $_ ->[0] } sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2] } map { my @cols = split /\t/; [ $_, $cols[8], $cols[21] ] } @foo; print "$_\n" foreach @sortedarry;