in reply to capture psudo tags

a) You can't parse arbitrary (HT|SG|X)ML with just regular expressions; you need a full blown parser. Your approach is pretty much doomed to failure to begin with.

b) You'd probably be better served as a learning experience using one of the already existing templating solutions (TT2, Mason, one of the wiki formatters; see Template, HTML::Mason, Text::WikiFormat) than attempting to roll your own from scratch.