in reply to pattern matching

One reason that jumps out at me is that the pattern character, '.' won't normally match a newline.

If you append the '/s' modifier to your regexes it changes the behavior such that '.' will match newlines (see perlman:perlre). Try this:

if ( /if.*?\{/s .. /.*?\}.*?else/s ) { s/\{//; s/\}//; }

This, of course, assumes that you have the entire if-else construct in $_ to begin with.

Update: fiddled with text.

Update 2: removed extraneous $_ bindings in substitutions and escaped the curly braces (nice catch, Zaxo).

dmm

You can give a man a fish and feed him for a day ...
Or, you can
teach him to fish and feed him for a lifetime