my %hash; while () { chomp($_); my ($first, $second) = split(/s+/, $_); push(@{$hash{$first}}, $second); } foreach my $key (keys %hash) { print "The $key is: ", join(', ', @{$hash{$key}}), "\n"; }