my %whole_file; while () { my %info = ( line_number => $., line_text => $_, atoms => split /\t/ ); $info{key} = $info{atoms}[1]; push @{$whole_file{$info{key}}}, \%info; # you can print out a tick every 100 or whatever here, using $. } my @dupes = grep { scalar @$_ > 1 } values %whole_file; # to see what data structure I just built, dump it via your favourite dumper. Mine is: use Data::Dumper; print Dumper(\@dupes);