c:\test>perl -ple"s[^(.*)$]{ $1 =~ m[DOG] ? 'DOG' : 'Not found' }e" junk.dat DOG DOG Not found DOG Not found DOG DOG DOG DOG