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


in reply to Replacing string with regexp without using modules

For your first question:
sub prog_replace_string { my ($replace_this, $with_this, $string) = @_; $string =~ s{\Q$replace_this\E}{$with_this}g; $string; }
For your second:
sub replace_vars { my ($string, $hash) = @_; $string =~ s{\$(\w+)}{$$hash{$1}}ge; $string; } my %vars = ( a => 1, b => 22, c => 333 ); print replace_vars('a: $a, b: $b, c: $c', \%vars);