in reply to Forcing array context

The @{[$string]} construction does not correspond to what you want. It evaluates to an array of one element, a copy of the value of $string. I don't quite see what you're attempting with the second try. A string in list context is a one element list.

The perlish way to treat the characters of a string as an array is to produce the array with my @str_ary = split '', $string;, but that does not help you modify the characters of $string in place, as the C char * as array construction would.

You're best bet is with substr. Letting sub fiddle {} take a character and return whatever you wish,

my $index; while ( $index < length( $string) ) { substr( $string, $index, 1) = fiddle(substr( $string, $index, 1)); $index++; }
That isn't nearly as tidy as pointer indexing, but perl is just not as close to the metal as C.

Note that &fiddle can return empty or strings longer than one character, and the changed length will be handled. That is probably an invitation to code with mysterious behaviors, and non-termination is possible.

After Compline,
Zaxo