my %hash; while (<>) { my ($id,$time) = split /,/; push @{$hash{$id}}, $time; } for (keys %hash) { print "@{$hash{$id}}\n"; }