use strict; use warnings; my $fhi; my %data; open $fhi, '<', 'file_A.txt' or die "can not open file file_A.txt: $!"; while (<$fhi>) { chomp; my @cols = split /\t/; $data{$cols[2]} = "@cols[2..3]"; } close $fhi; open $fhi, '<', 'file_B.txt' or die "can not open file file_B.txt: $!"; open my $fho, '>', 'file_B_out.txt' or die "can not open file file_B_out.txt: $!"; while (<$fhi>) { for my $k (keys %data) { s/$k/$data{$k}/g; } print $fho $_; } close $fho;