... my @seq; # read past the header while(){ last if /^Sequences producing/; } # assuming remaining data is fixed while(){ chomp; next if /^\s*$/; # capture the score /^.{67}\s*(\d+)/; # push anonymous array - [score,line] push @seq, [$1,$_]; } close IN; print join $/, ( map { $_->[1] } # print original line sort { $b->[0] <=> $a->[0] } # sorted by score @seq )[0..9]; # top ten