my %hash; my $buf; local $_; while (<$fh>) { chomp; if (my ($key) = /^>(\w+)/) { $hash{$key} = ''; $buf = \$hash{$key}; } else { $$buf .= $_; } }