#!/usr/bin/perl -w use strict; my %hash; while () { my($id,$value)=split; push @{$hash{$id}}, $value; } foreach my $id (sort{$a<=>$b} keys (%hash)) { print "id=$id values=@{$hash{$id}}\n"; } #prints: #id=1 values=3 2 10 #id=2 values=5 6 #id=3 values=4 __DATA__ 1 3 1 2 1 10 2 5 2 6 3 4