The following is a clean up of your code. There are cleaner ways of doing this. Once you start using use strict
and use warnings
many, if not all, of your issues will disappear.
use strict;
use warnings;
open (my $INF, '<', 'data.txt');
my %codes;
my $Sep = qr/\t/;
while( my $line = <$INF>){
chomp $line;
my $A_ID = (split($Sep, $line ))[0];
push @{$codes{$A_ID}},$line ;
}
close $INF;
my %match;
open (my $IN, '<', 'data2.txt');
while( my $line = <$IN>){
chomp $line;
my ($bA_ID, $name) = split $Sep, $line;
if (exists($codes{$bA_ID})) {
foreach my $codes_line (@{$codes{$bA_ID}}) {
my ($Name,$B_ID) = (split($Sep, $codes_line))[1,2];
my $new_array = join("\t", $bA_ID, $B_ID, $Name);
$match{$new_array}++;
}
}
}
close $IN;
print "Number of matched : ".keys(%match)."\n";
open (my $OUT,">", "Code_Match.txt");
print $OUT "$_\n" foreach keys(%match);
close $OUT;