my %new_data = (); foreach ( @DATA ) { my ($hostid, $rest) = split /\t/, $_, 2; push @{$new_data{$hostid}}, "$hostid\t$rest"; }