in reply to Comparing HTML snippets
HTML::TreeBuilder creates a very complex doubly linked tree. Very useful if you want to parse HTML, and walk between nodes in the parse tree, but less helpful if you are trying to find differences between two bits of HTML.
If you have two bits of HTML that are identical except for white-space (capitalisation, etc), then HTML::TreeBuilder should return identical trees for them, but there is a slight difference, then I think you will find it hard to find the difference by comparing the trees. For example if you use is_deeply out of Test::More it will find an enormous number of differences and then show you the first one it finds that is unlikely to be helpful to your problem.
Perhaps a better solution would be to not use perl, and instead pipe your HTML samples through a tool like html-tidy and then do a text diff of the output.