A: 

I'm no good with regular expressions, but this sounds like a job for them. I imagine a regex would sort this out for you quite easily.

Have a look at the RegexKitLite library.

Jasarien
Thanks, yeah someone else referred me to that library. (I didn't downvote you).
Jorge Israel Peña
A: 

If you want to be able to parse Wikitext in general, you have a lot of work to do. Just one complicating factor is templates. How much effort do you want to go to cope with these?

If you're serious about this, you probably should be looking for an existing library which parses Wikitext. A brief look round finds this CPAN library, but I have not used it, so I can't cite it as a personal recommendation.

Alternatively, you might want to take a simpler approach and decide which particular parts of Wikitext you're going to cope with. This might be, for example, links and headings, but not lists. Then you have to focus on each of these and turn the Wikitext into whatever you want that to look like. Yes, regular expressions will help a lot with this bit, so read up on them, and if you have specific problems, come back and ask.

Good luck!

Tim
Thanks I appreciate the response but I don't want to parse the entire wikipedia markup, just that bit that I posted, and it will usually only contain that type of markup. Assume that's the only type of markup that will appear. Sorry for the confusion!
Jorge Israel Peña
+2  A: 
Kendall Helmstetter Gelner