in reply to trouble matching

I have not looked at your code carefully but this is what i understand from your description. You have bunch of keywords to be replaced (stored in one file). Then you check for them in another file (2nd file) and write it out to a 3rd file. The code below should get you started. I have not taken care of all the details but it should give you enough idea on how to make changes to the code -

NOTE: Code not tested

#!/usr/bin/perl -w my %lookup = (); # Construct the lookup table while (<INFO>) { chomp; my @list = split; # assuming space separated $lookup{$list[0]} = $list[1]; # search => replace } # Go through the search file and check for lookup strings using # the hash and replace it with the hash-value while (<SRCHFILE>) { for my $k (keys %lookup) { s/$k/$lookup{$k}/g; } print; }

Picking a keyword from a file and then searching for it in the other file and re-reading them it very inefficient. If the first file is manageable i would use a hash as in above example