$ perl -E ' > $rowTxt = ( q{0123456789} x 2 ) . q{0123}; > @groups = $rowTxt =~ m{.{1,10}}g; > say for @groups;' 0123456789 0123456789 0123 $ #### $ perl -E ' > $rowTxt = ( q{0123456789} x 2 ) . q{0123}; > @groups = $rowTxt =~ m{(?=(.{10}))}g; > say for @groups;' 0123456789 1234567890 2345678901 3456789012 4567890123 5678901234 6789012345 7890123456 8901234567 9012345678 0123456789 1234567890 2345678901 3456789012 4567890123 $ #### $ perl -E ' > $sa = q{abcdefg}; > $sb = q{abbdegg}; > $df = $sa ^ $sb; > say q{Zero-based counting}; > 1 while $df =~ m{\x01(?{ say pos( $df ) - 1 })}g; > say q{One-based counting as per OP example}; > 1 while $df =~ m{\x01(?{ say pos $df })}g;' Zero-based counting 2 5 One-based counting as per OP example 3 6 $