http://www.perlmonks.org?node_id=702537


in reply to Re^2: Replacing string with regexp without using modules
in thread Replacing string with regexp without using modules

Could it be the hash reference ...?

Yes, in pc88mxer's code, $hash is a hash reference, so it must be dereferenced. In your case, it's a normal hash.  So either don't dereference

$hash{a} = "go"; $string =~ s{\$(\w+)}{$hash{$1}}ge;

or create a reference

$hash->{a} = "go"; $string =~ s{\$(\w+)}{$$hash{$1}}ge;

or even use the normal arrow syntax in both the assignment $hash->{a} = ..., and when you access it $hash->{$1}:

$hash->{a} = "go"; $string =~ s{\$(\w+)}{$hash->{$1}}ge;