#!/usr/bin/perl -w use strict; my $ip = '192.168.1.4; my $txt = 'Removed ' . $ip . ' by Dru'; my $file = '/data/syslog/log.backup'; open (FILE, "+<$file") or die "Can't open $file: $!\n"; while (){ if (/.*\b$ip\b.*/){ # I thought this would work, but it doesn't s/$_/$txt/; print FILE; } }