use strict; use warnings; my %hash; while () { if (/>([\w]+) /) { } else { chomp; $hash{$1} .= $_; } } for (sort keys %hash) { print "$_ => $hash{$_}\n"; } __DATA__ >EP11110 (-) TGCAATCACTAGCAAGCTCTC GCTGCCGTCACTAGCCTGTGG >EP40005 (+) GGGGCTAGGGTTAGTTCTGGA NNNNNNNNNNNNNNNNNNNNN