use warnings; use strict; my $str = "abc"; my $last_pos =0; while ($str =~ m/.|$/gc) { my $curr_pos = pos($str); printf("1: %d", $curr_pos); ($curr_pos == $last_pos) ? print " EOString\n" : print "\n"; $last_pos = $curr_pos; } __END__ 1: 1 1: 2 1: 3 1: 3 EOString