#! perl -slw use strict; my (%hash,@order); while() { chomp; my @bits = split /\t/; push @order, $bits[0] unless exists $hash{$bits[0]}; $hash{$bits[0]} .= ' ' . $bits[1]; } print "$_\t$hash{$_}" for @order; __DATA__ text1 text-a text2 text-b text3 text-c text1 text-d text3 text-e text3 text-f