/e is your friend but don't get too friendly:
#!/bin/perl -w use strict; my $string="hello <tag> code goes here </tag> "; $string=~ s{(<tag>.*?</tag>)}{replace( $1)}egs; print $string; sub replace { my $text_in_tag= shift; $text_in_tag=~ s{\n}{<br />}g; return $text_in_tag; }
The e modifier means that the replacement expression is eval-ed instead of being treated as a string. Hence $1 is replaced by replace( $1)
You can also use the old function-in-a-string trick:
$string=~ s{(<tag>.*?</tag>)}{@{[replace( $1)]}}gs;In reply to Re: Editting Part of Regex
by mirod
in thread Editting Part of Regex
by mt2k
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |