if (/BEGIN PATTERN/ ... /END PATTERN/) #### Code Snippet: # Beginning pattern: 'if' followed by 0 or more characters #followed by the nearest { brace # # Ending pattern: 0 or more chars. followed by nearest # } brace followed by an 'else' if ( /if.*?{/ .. /.*?}.*?else/ ) { $_ =~ s/{//; $_ =~ s/}//; } ----------------------------------------------------- Here is the text I am reading: if (c=e) { // delete this curly brace call pgme; call pgmd; } // delete this curly brace else {call pgmd; // keep these curly braces call pgmc;} I want the text to be changed to the following: if (c=e) call pgme; call pgmd; else {call pgmd; call pgmc;}