while () #this is my opened file { { next if /^\s*File/; #remove line starting with filename my ($id, $seq) = split; # The my is important push @{$species{$id}}, $seq; } } # later... while ( ($key, $sequence) = each %species ) { print $key, "\t", join ":", @$sequence; } # Which will out your key, followed by a tab, # followed by all your sequences (however many # there are) separated by colons