My problem is I don't know how to use hash keys and values as variables. For example s/$v/$k

Next, I'm not sure how to even approach it as I think I would have to loop through the message text while looping through the hash keys for the substitution. So I think I would have a while statement for the file and a foreach statement for the hash but everytime I try to code it I can't seem to progress beyond the "hmmmmm: stage.

You don't need a while statelement to look the the value associated with a key in a hash.

Basically, what you have to do is to read your input file, to split every line of your input into single letters, and, for each letter, look for its translation in the hash, and print out the translation.

The purpose of the parenthesis in the regexpr is to "capture" the text matched by pattern between them. The text captured by the first (in this case only) set of parenthesis is available as a special perl variable "$1". The character class between the parenthesis matches a single lower-case character. This is captured into $1 and used as the key into the translation hash in the substitution field. The corresponding hash value then replaces original character. The "/g" at the end tells perl to repeat the process as often as possible.

Note: Although not used here, perl has analogous special variables $2, $3,..... to capture text from the second, third, etc. pair of parenthesis. Good Luck, Bill