in reply to HTML::TreeBuilder

Use the $tree->content_list method and concatenate all the non-element nodes, so get just the text for this element. The full list of methods can be seen in the documentation for HTML::Element.
$text = join '', grep { not ref $_ } $tree->content_list;

--
integral, resident of freenode's #perl