 <p>Your substitution will look like this:</p> <pre><code>s#^.*\s(remote\.host\.tld)\s*$#$ip_to_update\t$1# </code></pre> <p>Replacement can be done in one line:</p> <pre><code>perl -i -wpe "BEGIN{$ip=`awk {'print \$5'} /web_root/ip_update/ip_update.txt`} s#^.*\s(remote\.host\.tld)\s*$#$ip\t$1#"' </code></pre>