The main concern you must have when dealing with map and a regex is not destructing the original array unless you truly intend to. $_ is an alias to each element of the source array, so any modification of it modifies the original array. To avoid this we assign to a temporary lexical in the above map block. And then finally make sure to return the actual variable and not a count of the number of substitutions.
Personally, I'd probably just stick with your original code, as I kind of doubt that you truly need a second array with these crunched values. Instead simply add the "crunching" as part of the loop for whatever other processing that you intend to be doing. Whatever that may be.
thanks guys, it's working.
I still dont' understand map too well(along with many other things).. can someone show me a URL that has map tutorial better than http://perldoc.perl.org/functions/map.html ??
Their explanation on how to mix it in with other does not make much sense to me.
You should take a bit of time to browse through the Tutorials section here. Of immediate interest you will find Map: The Basics there and the List Processing, Filtering, and Sorting sub-section in general is likely to be of value. But don't stop there - you will find lots of good stuff if you poke around the many corners and alcoves of the Tutorials section.