sub foo { my @copy = @_; for (@copy) { my $counter; s/(.)/chr ++$counter + ord $1/ge; } return @copy; } print foo('asdf');