in reply to HTML::TreeBuilder dropping end tags
It occurs to me, despite you already having found the solution to your problem, that if you are producing XHTML then you might be better off treating as XML and using something like XML::Twig for instance, you might find this gives yoy a greater deal of flexibility.
/J\
|
|---|