in reply to Search and Replace in one file based upon contents of another

Since you won't provide test data, I'll claim this is untested :)

#!/usr/bin/perl # http://perlmonks.org/?node_id=1174798 use strict; use warnings; # read in mapping hash my %iphash = split ' ', do {local (@ARGV, $/) = 'file_2'; <>}; # construct pattern to match keys of mapping hash my $ips = join '|', map quotemeta, sort keys %iphash; my $pattern = qr/\b($ips)\b/; @ARGV = 'file_1'; while(<>) { s/$pattern/$iphash{$1}/g; # do the mapping anywhere in the line print; }