use Regexp::List qw( ); my $re = Regexp::List->new()->list2re(keys %dict); s/$re/$hash{$1}/g;