$text =~ s/|$) # closing script tag or the end of the text ($) //xgis; # (x) comments (g)lobal, case (i)nsensitive, # treat string as (s)ingle line # uncommented version $text =~ s/|$)//gis;