my @sorted = map {$_->[0]} sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } map {chomp;[$_,split(/\t/)]} ; print OUT "$_\n" for @sorted;