What's with this:
while(list(,$type) = each($types)) {
? Why not just this:
foreach($types as $type) {
I'm not sure if your code will work or not, as I've never done it like that before. A simple [man]foreach/man looks a lot cleaner though.
As for the preg_match_all, I'm not too savvy with Perl regular syntax, so I can't really help you there 🙁