in reply to BBCode parser/validator needed

You could try the BBCode::Parser module from CPAN that seems to do what you want. Also if you want XHTML parser, there are quite a few on CPAN as well.

Rule of thumb - always check CPAN first to see if there is already a module to do what I want. The chances are that it already exists.