$text =~ s/\|\|(.*?)\n/\<\!\-\-$1\-\-\>\n/g; #turn line comment form into XML comment form $text =~ s/<\!\-\-(.*?)\}(.*?)\-\->/<\!\-\-$1 endbrace $2\-\->/gxs; #escape the end braces in comment so they needn't be balanced $text =~ s/<\!\-\-(.*?)\{(.*?)\-\->/<\!\-\-$1 openbrace $2\-\->/gxs; #ditto for open braces