qr{ <% [^%]* %+ ( [^>%] [^%]* %+ )* > }x; #### # Test Script #Uncomment this next line for WAAAYYY too much info #use re 'debug'; $cleanup= qr{ <% [^%]* %+ ( [^>%] [^%]* %+ )* > }x; @test= ( "stuff <% junk %> more stuff <% more junk %> end", "stuff <% junk% %> more stuff", "Go <% now %> to <% your %> home <% if %> you <% can %>", "<% %%>", "<%replace here%%>but not here%>", "1 <% xxx%%> 2 <%%> 3 <%>%> 4 <% >% %> 5 <%%%% xxx %%%%> 6 ", "<% %%> %>", "<%abcdefg>"x500, "<% %% %>"); foreach(@test) { print "-"x60,$/,"Test: {$_}$/"; s/$cleanup//g; print "Result: {$_}$/"; }