$_ = 'Hello World'; my %h = ( e => 'b', l => 'd', ); my $k = join '|', keys %h; s/([$k])/$h{$1} || $1/eg; print
I think you want either ($k) or my $k = join '', keys %h; in the latter case one would probably also want to check that the keys are actually single letters. In both cases || $1 wouldn't be necessary any more, since the match would necessarily be one of the keys.
In reply to Re^2: simple letter substitution according to hash
by blazar
in thread simple letter substitution according to hash
by DavidC
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |