This is correct but not maximally efficient. Why create a separate sub for each s///? It's more efficient to just build one sub containing all the substitutions. Also, why localize and return $_? Operating on it directly is more efficient. See my solution below for an example of what I'm talking about.