... am I missing something?
You're missing what BrowserUk said here, an approach that processes an entire line at a time.
The next part to think about is what happens if you encounter a 'word' in a line that doesn't exist in your translation hash, e.g., the line
"peaches,peaches,foobar,kiwis\n"
(hints: exists, next, maybe // (defined-or) or ?: (ternary/conditional operator) – see perlop for the latter two).
In reply to Re^3: using hashes
by AnomalousMonk
in thread iterating hash keys?
by R56
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |