use strict; my %hash = (); my ($first, $second); while () { ($first, $second) = split; push (@{$hash{$first}}, $second); # from Perl Cookbook 5.7 } while ((my $key, my $value) = each %hash) { print "the Key is: $key\n"; print join("\n",@$value),"\n\n"; } __END__ 5 25 6 27 5 24 5 23 6 29 6 30 4 22 5 25 6 27 4 22 4 21