my @officialannotation = (); # An empty list. NOT [] , which is an empty array-ref my $offgenes; open(my $infile , "<", "genbankfile.txt") or die "cannot open file genbankfile.txt $!"; while(<$infile>) { $offgenes++ if ($_ =~ /\d+/) ; my ($start, $stop) = split; push @officialannotation, {start=> $start, stop => $stop}; } close $infile; #.. collect the other one in the same way # Then compare the 2 arrays of hashrefs : for my $p (@prodigalannotation){ next unless my ($candidate) = grep {$p->{start} eq $_->{start}} @officialannotation; $exactmatching++ if $candidate->{stop} eq $p->{stop}; }