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


in reply to replace a character based on rule file

The reason the OP code doesn't work is that the @inp_word array contains elements of one character each, because it gets the output of split(//,$inp_word4); But then your logic depends on some element of @input_word containing "na", which can never happen.

If I understand your task description correctly, I think you just need a basic regex substitution:

while(<>) { s/(?<=na)m/+d/g; print; }
The (?<=na) part there is called a "positive look-back assertion" - check that out on perlre. It says that any "m" will be replaced by "+d" if it's preceded by "na".