a1 b1 c1 d1 a2 b2 c2 d2 a3 b3 c3 d3 a4 b4 c4 d4 #### #!/usr/bin/perl open (datafile, "file_A.txt"); @fileinput = split("\t", ); for ($i = 2; $i <=200;){ open(OF, "file_B.txt"); #file_B.txt contains the original file open(NF, ">file_B_out.txt"); #file_B_out.txt contains the processed output while ($line = ) { print "$fileinput[$i]\n"; print "$i\n"; $line =~ s/$fileinput[$i]/$fileinput[$i+1]/g; #print $line; print NF $line; } $i=$i+4; } close(NF); close(OF);