in reply to help requested with collating data from two files

Your chop'ing the element in @file2 waaaay too many times. Had you use the recommended chomp, all you have have lost is CPU cycles. With chop, you're loosing data.
use strict; use warnings; my $file1 = shift; my $file2 = shift; open(my $fh1, '<', $file1) or die "Cant open $file1: $!\n"; open(my $fh2, '<', $file2) or die "Cant open $file2: $!\n"; chomp( my @file1 = <$fh1> ); chomp( my @file2 = <$fh2> ); my %counts; for my $base (@file1) { my $re = qr/^\Q$base\E(\.|\z)/; for my $node (@file2) { ++$counts{$base} if $node =~ /$re/; } } for my $base (keys(%counts)) { print("$base: $counts{$base}\n"); }
or even
... my %counts; for my $base (@file1) { my $re = qr/^\Q$base\E(\.|\z)/; $counts{$base} += grep /$re/, @file2; } ...