Maybe you want to use a proper HTML parser, like HTML::Parser instead?
In reply to Re^3: Help with RegEx by Corion in thread Help with RegEx by mr_p