in reply to substituting values in an array

You are treating numbers as strings. Is it intentional that you want stringy-semantics on your comparisons? Regardless, the standard way to transform an array is via map. This isn't a job for tr, or for s///. If I understand your intent, you want to take an array of numbers, and constrain it such the all elements are 200 or less. Any element over 200 becomes 200.

my @array = ( 200, 201, 205, 194, 140, 250, 280 ); my @constrained = map { $_ > 200 ? 200 : $_ } @array; print "@array\n";

I understand you've been searching a long time on how to do this. Sometimes better than searching is asking yourself, "How would I do this on paper?" If I were doing it on paper, I would look at an element, and then make the decision, "Is the element greater than 200?" If it is, write down 200. If not, write down the original element. Great. Now we know how we would do it on paper; let's put it to code... and that produces what you see above.


Dave