#!/usr/bin/perl -w use strict; my %seen; my @data; open (INPUT,"file") or die "Error accessing file : $!"; while () { chomp; my ($col1, $col2) = split /\t/; if (exists $seen{$col1}) { $data[$seen{$col1} - 1] .= " $col2"; } else { $seen{$col1} = push @data , "$col1\t$col2"; } } print "$_\n" foreach(@data);