in reply to Question on Html Tidy

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.