my %hash; # crappy name but easy to remember while () # assuming FILE is open to the right place { my ($key, $value) = split /\t/; # only one tab per line push @{$hash{$key}}, $value; # magic of autovivification } # done, print everything foreach my $key (keys %hash) { print $key, " => ", join(' ', values @{$hash{$key}}, "\n"; }