how to do search and replace on text files in directory

I was google searching and found

Perl as a command line utility tool

This almost solves my problem:

find . | xargs perl -p -i.old -e 's/oldstring/newstring/g'

I think this would create a new file for every file in my directory tree. Most of my files will not contain oldstring and I don't want to make a copy of them.

How would I filter it thru grep first so I only perform search and replace on those files that have something to replace?

Also: how do I avoid running perl on directories. I looked at the "man find" on cygwin (sorry, I'm using cygwin on windows, please don't shoot me).

I tried

/usr/bin/find . -empty -prune

but this did not omit the directory files. Is this a bug in cygwin? I don't want to run perl on my directory files!

Thanks,
Siegfried

You can try this; make a backup of your files or playaround with it first though:

find . -type f -exec grep -l oldstring {} \; | xargs ...