for my $i ( 0 .. $lengthString - 1 ) { for my $j (0 .. $numChars - 1){ // The following line does not work my $char$j = substr( $string$j, $i, 1 ); } }