in reply to select strings with biggest length

This may not be a good way to process the sequences, especially if your file is large. However, just to show another way, you can read the whole file into $_ and pull the protein name/sequence pairs out using a regular expression. Then split them on newline in a map, pass into a sort so as to get the pairs in ascending sequence length and finally map the pairs out and assign to a hash. Thus, if there are any duplicate proteins the longest sequence will be assigned to the hash last, overwriting any previous shorter sequence.

use strict; use warnings; use Data::Dumper; { local $/; $_ = <DATA>; } my %sequences = map { $_->[0], $_->[1] } sort { length $a->[1] <=> length $b->[1] } map { [split m{\n}] } m { > ( [^\n]+ \n [^\n]+ ) }gx; print Dumper(\%sequences); __END__ >protein1 ASFGTHTRHTHRHTHTRHTRHTR >protein2 ERYRYTRYHTRHTGEFEWWFEEFFFFREFRGRE >protein3 AWEERERGRGRGREGRGREGRRRRRRRRTTHTHTRHRHTRHTR >protein2 AASEFEFEFE >protein4 REYTRHTRGRVEVCREVR

Here's the output

$VAR1 = { 'protein4' => 'REYTRHTRGRVEVCREVR', 'protein2' => 'ERYRYTRYHTRHTGEFEWWFEEFFFFREFRGRE', 'protein1' => 'ASFGTHTRHTHRHTHTRHTRHTR', 'protein3' => 'AWEERERGRGRGREGRGREGRRRRRRRRTTHTHTRHRHTRHTR' };

I hope this is of use.

Cheers,

JohnGG

Update: Used the x modifier and spaced things out a bit to aid readability.