in reply to Substringing HTML content

HTML::Filter or one of the other HTML::Parser modules might help.