in reply to replacing text with a function

Is this homework? The substitution operator (s///) is documented in perldoc perlop. Look for the option that allows you to specify an executable expression as the replacement string.

Also, there is no need to look for a match before doing the replacement. Just do the substitution.

--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';