my @lines; while ( { my @array = split; # Don't save first two fields push @lines, [ @array[2..5] ]; } # Sort 3 field from input for my $line (sort { $a->[0] cmp $b->[0] } @lines) { for my $value (@$line) { print "$value\t"; } print "\n"; } __DATA__ a b c d e f a b c d e f g h i j k l