open(OUT1, '>', $File4) or die("Can't create output file \"$File4\": $!\n"); open(OUT2, '>', $File5) or die("Can't create output file \"$File5\": $!\n"); %file2_data; { open($fh_keys, '<', $File2) or die("Can't open key file \"$File2\": $!\n"); while ($line1 = <$fh_keys>) { chomp($line1); $line1 =~ s/^\s+//; # Remove the space from begining of the line $line1 =~ s/\s+$//; # Remove the space from end of the line $first = (split /\t/, $line1)[0]; $file2_data{$first} = $line1; } } close($fh_keys); %file1_data; { open($fh_in, '<', $File1) or die("Can't open input file \"$File1\": $!\n"); while (<$fh_in>) { chomp; $flag = 0; $sec = (split /\t/, $_)[1]; $file1_data{$sec} = $_; if ($file2_data{$sec}) { print OUT1"$_\tFOUND_Data\t$file2_data{$sec}\n"; } else { print OUT1"$_\tNOTFOUND_IN_FILE2\n"; } } } close($fh_in); while ( ($KEY_1, $VALUE_1) = each %file2_data ) { if ($file1_data{$KEY_1}) { print OUT1"$file1_data{$KEY_1}\tFOUND_Data\t$VALUE_1\n"; } else { print OUT1"$VALUE_1\tNOTFOUND_IN_FILE1\n"; } } open my $File3_IN1, q{<}, "$File3" or die qq{Can't open "$File3": $!\n}; my @numbers = (); while (<$File3_IN1>) { chomp; $_ =~ s/^\s+//; $_ =~ s/\s+$//; if ($_ == "B") { push @numbers_B, $_; } els if ($_ == "C") { push @numbers_C, $_; } els if ($_ == "D") { push @numbers_D, $_; } } close($File3_IN1); close(OUT1); my $rxFindB = do{ local $" = q{|}; qr{(@numbers_B)}; }; my $rxFindC = do{ local $" = q{|}; qr{(@numbers_C)}; }; my $rxFindD = do{ local $" = q{|}; qr{(@numbers_D)}; }; open OUT1_IN2,"cat $File4 |" or die "Can't open $File4: $!\n"; while () { chomp; if m{$rxFindB} { print OUT2"$_\t$1\t"; } else { print OUT2"$_\tNOT_FOUND_B_InFile3\t"; } if m{$rxFindC} { print OUT2"$2\t"; } else { print OUT2"$_\tNOT_FOUND_C_InFile3\t"; } if m{$rxFindD} { print OUT2"$3\n"; } else { print OUT2"$_\tNOT_FOUND_D_InFile3\t"; } } close(OUT1_IN2);