in reply to how do i find unclosed tags ?

I find the easiest way to do this is to mark the closing tags with a unique character - I usually use an asterisk, but it can be any other character that doesn't exist in the rest of the file.
$lines =~ s/(<\/a>)/\*$1/gms;
Then I search for two open tags without that character between them.
$lines =~ /<a[^\*]*<a/gms;