When doing substitutions like this, /e is your friend. $text =~ s/\#\w+\#/$hash{$1}/eg; /e forces the right-hand side of the s/// to be evaluated as a Perl expression, and the result substituted for whatever the left-hand side matched. The boundary between interpolation and substitution can seem pretty hazy, but it makes a bit more sense if you imagine that the regexp is "compiled" immediately before it is executed. At that point, $1 either doesn't have a value, or holds a value from a prior regexp. Neither is what you want.
Consult perlre for full details.
In reply to Re: regex substitution
by dws
in thread regex substitution
by michellem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |