I'll be the first to admit that I suck with regular expressions. I consider myself to be pretty good in Perl, but for some reason the understanding of them have eluded me. I'm working on a BBS which has various internal codes which translate into the appropriate HTML when displayed, as most BBS's do in one form or another. The thing I'm working with makes an exception in the usual substitution.

So far I have this:

while ( $$text =~ /\[codes\].*?\[.*?\[\/codes\]/ || $$text =~ /\[codes\].*?\].*?\[\/codes\]/ ){
    $$text =~ s!\[codes\](.*?)\[(.*?)\[/codes\]!\[codes\]$1\&\#091;$2\[/codes\]!gi;
    $$text =~ s!\[codes\](.*?)\](.*?)\[/codes\]!\[codes\]$1\&\#093;$2\[/codes\]!gi;
Ironically, what I'm attempting to do is exactly what this BBS's 'code' tag does. The problem I'm having is that if I have multple code couples in the post, it deactivates all codes between the first open code tag and the last close code tag.

First.. is there anyway to avoid the while loop? I'm sure there is and it's probably something simple that I'm overlooking. Secondly, how to I have it stop the replacement at the first end code tag reached after the open tag?

Thanks in advance,
Dave Mittner
So-called programmer