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"; } #### use Set::Scalar; my %hash; while () { chomp($_); my ($first, $second) = split(/s+/, $_); if (!exists $hash{$first}) { $hash{$first} = new Set::Scalar(); } $hash{$first}->insert($second); } foreach my $key (keys %hash) { print "The Key is: $key\n\t", join("\n\t", $hash{$key}->members()), "\n"; }