while($str =~ /\G(.)/gs) { ... } ## or with substr() my $i = 0; while( defined(my $c = substr $str, $i++, 1 )) { ... }