Always a module for this kind of thing. It might feel like more work to set up but you will save yourself hours of learning the hard way otherwise.

You'll also need well formed block tags around your text. Strict XHTML doesn't allow naked flow tags in the body. There are a lot of ways to do this, the one I like a lot is using XML::LibXML as an XHTML filter/writer.

Semi-tested minimalist version. You'll have to manipulate/add headers and the <html/> yourself-

use strict; use warnings; use XML::LibXML; local $/ = "\n\n"; my $doc = XML::LibXML::Document->createDocument(); my $root = $doc->createElement("body"); $doc->setDocumentElement( $root ); while ( my $para = <DATA> ) { chomp $para; my $p = $doc->createElement("p"); my $txt = $doc->createTextNode( $para ); $p->appendChild($txt); $root->appendChild($p); } print $doc->serialize(1); __DATA__ Some arbitrary text > some fixed text & that's okay. XHTML is fun with L<XML::LibXML>.
Yields-
<?xml version="1.0"?> <body> <p>Some arbitrary text &gt; some fixed text &amp; that's okay.</p> <p>XHTML is fun with L&lt;XML::LibXML&gt;. </p> </body>
Update: LibXML can be a bit daunting. Here is a quicky you can use to just get the block level (the <p/>s) tags out of the document. print $_->serialize(1), $/ for $doc->getDocumentElement->childNodes;

In reply to Re: HTML escape char? by Your Mother
in thread HTML escape char? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.