in reply to puzzled by pos

jeffa's and zengargoyle's solutions both avoid an infinite loop, but miss the last character if the length is odd.
Here's my try.
#!/usr/bin/perl -w use strict; my $x="hello world"; # 11 chars while ( $x =~ /(.)(.)?/g ) { my ( $y, $z ) = ( $1, $2 ); $z = "" unless $z; # prevents the warning # "use of uninitialized ..." print"<$y:$z>\n"; } __END__ <h:e> <l:l> <o: > <w:o> <r:l> <d:>
"hello world!" is 12 characters long, and it works fine. Removing the bang at the end, it becomes 11 and the normal loop will fail.
But making the second match optional, the loop goes till the end, and the only other thing you need to do is to check if the second match is defined or not.

I don't see the need of bothering with either pos or the inchworm method (/\G   /g) in this case.
_ _ _ _ (_|| | |(_|>< _|