#!/usr/bin/perl use strict; use warnings; # Fake up a couple of files my $file_a = <}; # Slurp in all of file_b close $inB; open my $inA, '<', \$file_a or die "Can't open file_a: $!"; while (<$inA>) { chomp; my @parts = split /\t/; next if @parts < 4; $fileBStr =~ s/\b $parts[2] \b/$parts[2] $parts[3]/xgm; } close $inA; print $fileBStr; #### starting form the top of the file I need 1. to get the the value in the 3rd column (c1 d1) 2. search in a second file (file_B.txt, not tab delimited and quite messy) all the matches for it. 3. when a match is found, I would like to append to the current value (c1 d1), the value of 4th column (d1) in file_A.txt, separated by a space. 4. go back to the first file (file_A.txt), get the the value in the 3rd column in the second row (c2 d2) and do another round of search and insert the value of d2 in the second file (file_B.txt).