while (<>) { my ($key,$rest) = split; $hash{$key} ||= []; push(@{$hash{$key}}, $_); }