ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I do this as I may have hundreds of files that are not writable but need the update?

I'll be using this find command to search the files:

find . -type f -name "*" -exec grep -ls ABC {} \;

Then I'll be using sed or perl to change "ABC" to "XYZ" for example.

Some of the files will be writable and some won't. Thanks for any assistance you can give.

Only for not owner's writable files.

Before

chmod u+w file

After

chmod u-w file

Thanks but like I said I have mix of files that are writable and some that are not. For the ones that are currently writable I don't want to remove the write bit.
How can I update a many files of mixed permissions and preserve the original permissions after the update? Thanks!

index all files permissions in a file , then change permission and modify the files as you wish, then use the indexed file to change permissions back.