Your problem, I don't know. But you might want to check out HTML::Tidy, which I believe is a perl wrapper around that utility.

UPDATE: Actually, on closer inspection, I'm not so sure it's a wrapper around that utility... but still worth a look I think.

UPDATE 2: Corrected the link.

In reply to Re: Question on Html Tidy by tphyahoo
in thread Question on Html Tidy by vishi83

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