http://www.perlmonks.org?node_id=587129


in reply to How to substitute the elements in an array without changing the original array.

See map.
my @source = (1,2,3,4); my @dest = map { $_ * 2 } @source; print "@source\n"; print "@dest\n"; #Output: #1 2 3 4 #2 4 6 8
my @source = ('bob', 'joe'); my @dest = map { $_ eq 'bob' ? ucfirst($_) : $_ } @source; print "@source\n"; print "@dest\n"; #Output: #bob joe #Bob joe