That's not quite good enough... since something like this 2^4 + 3^3 would turn out as this 2<sup>4 + 3^3</sup> when it should be this 2<sup>4</sup> + 3<sup>3</sup>

There's a similar problem for parsing HTML. What if you want to get everything inside the "start" span tag like this: <span id="start">Outer span <span>inner span</span> more outer</span> <span>Second span</span>

If you want the whole first span tag, you can't just use /\<span id=\"start\"\>.*?\<\\span\>/ because it will terminate at the first /span, but you also can't use /\<span id=\"start\"\>.*\<\\span\>/ because it will terminate at the end of the last span.

Like I said: anything else will be much more difficult. Or at least with my limited experience it would be. Ask on www.perlmonks.com and see what suggests you get. Post back here if you get the solution. -------------------------------------------------