http://qs321.pair.com?node_id=196268

IOrdy has asked for the wisdom of the Perl Monks concerning the following question:

Rather than explain the following snippet should give you an idea of what I'm trying to do. I just can't quite get it going and respectfully ask for the help of the monks.

a) Is this right? I'm just trying to save writing the almost the same regex for every tag.
b) I can't figure out how to get the matched variables ($1, $2 etc..) into the text and I'm fresh out of ideas.

Code:
# ... my %taglist_complex = ( 'email' => "<a href='mailto:$1'>$2</a>", 'url' => "<a href='$1'>$2</a>", 'img' => "<img src='$1' alt='$2' />" ); my %taglist_simple = ( 'b' => '<b>$1</b>', 'i' => '<i>$1</i>', 'u' => '<u>$1</u>', 'url' => '<a href=\'$1\'>$1</a>', 'img' => '<img src=\'$1\' alt=\'$1\' />' ); # Process Complex Tags -> [url="http://www.foo.bar.com"]foobar[/ur +l] while (my ($tag, $regex) = each %taglist_complex) { $post =~ s/\[\s*$tag\s*=\s*['"]?([\w\W][^\]]*?)['"]?\](.[^\[|\ +]]*?)\[\s*\/\s*$tag\s*\]/$regex/gi; } # Process Simple Tags -> [url]http://www.foo.bar.com[/url] while (my ($tag, $regex) = each %taglist_simple) { $post =~ s/\[\s*$tag\s*\](.[^\[|\]]*?)\[\s*\/\s*$tag\s*\]/$reg +ex/gi; } #...