#! /usr/bin/perl use strict; use warnings; my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] } map { [ $_, map { defined $_ ? $_ : 0 } (split /\s+/, $_)[1,5,7] ] } ; use Data::Dumper; print Dumper \@sorted; __DATA__ locus 1 transcript 3/12 confidence 11.000 length 238 locus 2 transcript 3/12 confidence 12.000 length 238 locus 5 transcript 3/12 confidence 15.000 length 238 locus 3 transcript 3/12 confidence 13.000 length 238 locus 6 transcript 3/12 confidence 16.000 length 238 locus 4 transcript 3/12 confidence 14.000 length locus 1 transcript 3/12 confidence 11.000 length 138