use strict; use Data::Dumper; my %hash; while() { chomp; my $line = $_; my $key = (split/\t/, $line)[0]; push @{ $hash{$key} }, $line; } print Dumper(\%hash); __DATA__ 1 a 101 1 b 110 2 c 201 3 d 301 3 e 310 3 f 320 4 g 401