in reply to String replace - Part II

Why do you need to do this all with regexes? Can you do something like this?
if (/func1/) { s/blah/blah/ } elsif (/^#define/) { s/yak/yak/ } else { s/mumble/mumble/ }
Your examples look like C code. If your requirements are very complex, you may need to use a more advanced parser design -- parsing C with just a regex is not possible.