Can't you do this with HTML::Parser, and a flag stating when you are and aren't "inside" a tag? Have your start() routine set/increment the flag, and the end() routine unset/decrement it, and the test() routine trap it or not based on the flag.
You'd have to watch for and deal with nested tags, but I don't see why it wouldn't work.