in reply to Re: Replacing a search/not found pattern with a word
in thread Replacing a search/not found pattern with a word

Simpler:
perl -nle"print /(DOG)/ ? $1 : 'Not found'"
Or if you wanted to keep the -p:
perl -ple"$_ = /(DOG)/ ? $1 : 'Not found'"

Replies are listed 'Best First'.
Re^3: Replacing a search/not found pattern with a word
by jwkrahn (Abbot) on Mar 23, 2008 at 06:47 UTC

    I can shave a couple of strokes off of that:

    perl -lpe'$_=/DOG/?$&:"Not found"'