I would try a CPAN module like HTML::Tree.
non-Perl: Andy Ford
In reply to Re: Brief question: m// and nested HTML tags by andyford in thread Brief question: m// and nested HTML tags by mdunnbass