in reply to
Another "out of memory!" problem
My guess would be that you are leaking memory because you are not destroying your HTML::Treebuilder objects properly. From the docs:
4. and finally, when you're done with the tree, call $tree->delete() to erase the contents of the tree from memory. This kind of thing usually isn't necessary with most Perl objects, but it's necessary for TreeBuilder objects. See HTML::Element for a more verbose explanation of why this is the case.
A simple undef() is not enough.