use strict; use vars qw($outfile); open(DATA, $ARGV[0]) or die "Couldn't open $ARGV[0]: $!"; $outfile = "test.txt"; open (OUT, ">$outfile") || die "Can't open $outfile for creation: $!\n"; my (%hash,@order); while() { chomp; my @bits = split /\t/; my $first = "$bits[0]"; push @order, $first unless exists $hash{$first}; $hash{$first} .= ' ' . "$bits[1] $bits[2]\t"; } print OUT "$_\t$hash{$_}" for @order;