I just had to add a bit more to this.
The alternate form of the code that would have helped jeffa
the most was:
With the split and substitution reversed, you would have
discovered quite quick that s/// and tr/// always return
counts, even in the list context that map provides.
I bet you have seen foreach (/PATTERN/) {} and figured
that s/// and tr/// work like m// does in that idiom.
Read a bit of `perldoc perlop` and you will find that in
the section "Regexp Quote-Like Operators" it explains
m// behavior in a list (returns the list of matches) but
makes no such claims about the other two.
This has bit me before. =)
BTW, with your first example and with the others that were
provided, you should also do a:
And note the side effects of your code on your original data.