If you want to just turn HTML into something that will display as plain text, then you don't really need to parse it. Instead just use the HTML::Entities module's encode_entities() function. (Included with recent Perls, type perldoc HTML::Entities at the command line, if that gives you documentation then you have it.) If you have it then you can use it as follows:

use HTML::Entities; # Insert much code here my $escaped_html = encode_entities($raw_html); # Insert the rest of your program
If you want to retain the formatting, then you have to work harder. The simplest solution is to just surround the included HTML with pre tags. Another common solution is to turn returns into br tags and leading spaces into   tags. You can also use the textbox solution that was already given, but it only works with arbitrary HTML if you already have escaped it. (Otherwise nothing stops the HTML from having a closing textbox tag to mess you up.)

In reply to Re (tilly) 1: how to force HTML to display as text by tilly
in thread how to force HTML to display as text by Summers_Azin_pr0n

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.