use strict; my $head; my %hash; while (<>) { $head = (split)[0]; push @{$hash{$head}}, $_; }