in reply to Matching column in different files to create a third one

With well formatted input, this sort of task is fairly simple. However, as toolic points out, your lack of formatting makes this unnecessarily difficult. If I assume your files are:

file1.txt:

SNDK 80004C101 AT XLNX 983919101 BB NETL 64118B100 BS AMD 007903107 CC KLAC 482480100 DC TER 880770102 KATS ATHR 04743P108 KATS RBCN 78112T107 JT TXN 882508104 KATS STM 861012102 KATS

file2.txt:

AT AU AU AU AV AT BB BE BS BR BSE HU BZ BR CC CL CD CZ CG CN

and I assume the mappings of 1st to 2nd column in file 2 are many to one(so I can use a hash), then you'll likely want something like this:

#!/usr/bin/perl use strict; use warnings; my %mapping; open my $key_handle, '<', 'file2.txt' or die "Open fail: $!"; while (<$key_handle>) { my ($key, $value) = split; $mapping{$key} = $value; } open my $data_handle, '<', 'file1.txt' or die "Open fail: $!"; open my $out_handle, '>', 'file3.txt' or die "Open fail: $!"; while (<$data_handle>) { my @columns = split; print $out_handle "$columns[0]\t$columns[1]\t$mapping{$columns[2]} +\n" }

However, my guess at your file 1 contains the string 'KATS' multiple times in what I guess was column 3 and never appears in your file 2. Given the distribution of 'KATS' in your specified file 1, this mapping is impossible unless file 1 contains only one line.