Unless it is a small bit of code, don't waste your time escaping...use qq instead:
This is text<br>that does not need escaping, even if it is "quoted" or "quoted" or <quote>quote</quote><br><br>even email@resses~;
Note that it begins with print qq~
and ends with ~;
, and will save you huge amounts of time when dealing with exceedingly large amounts of content.