#! perl -slw use strict; use Data::Dumper; my %map = map{ split /=/, $_, 2 } split /\n/, do{ local $/; }; print Dumper \%map; while( <> ) { chomp; if( m[http://([^/]+)/(\W?)]i ) { next unless defined $map{ $1 }; substr( $_, $-[0], $+[0] - $-[0] ) = 'http://' . $map{ $1 } . ( length $2 ? $2 : "\n$2" ); } print; } __DATA__ www.theirsite.com=our.server1/theirsite/ www.dummy.com=our.server2/dummy/ #### P:\test>type junk.txt http://www.theirsite.com/ http://www.dummy.com/ http://www.theirsite.com/stuff http://www.dummy.com/stuff http://www.theirsite.com/ stuff http://www.dummy.com/ stuff P:\test>perl 324406-2.pl < junk.txt $VAR1 = { 'www.theirsite.com' => 'our.server1/theirsite/', 'www.dummy.com' => 'our.server2/dummy/' }; http://our.server1/theirsite/ http://our.server2/dummy/ http://our.server1/theirsite/ stuff http://our.server2/dummy/ stuff http://our.server1/theirsite/ stuff http://our.server2/dummy/ stuff