# Use strict and warnings, etc # Read the file and hash it my %data; while (<>) { my ($k, $v) = split /\t/; # Split on tabs my $values= $data{$k} ||= []; # ensure we have an array ref push @$values, $v; # add the value to the end of list for this key } # Print out the results for (sort keys %file) { # Sort is optional print join "\t", ($_, @{ $data{$_} }); # Assuming you want them tab seperated print "\n"; }