foreach $tex_key (keys %allowed_text_code){ $text =~ s/\Q$tex_key\E/$allowed_text_code{$tex_key}/g; print $text. "\n"; }