$_ = "Hello there, people!"; @output = (); while (length) { (push @output, "word: $1"), next if s/^(\w+)//; (push @output, "spaces"), next if s/^\s+//; (push @output, "punc: $1"), next if s/^(.)//; die "how did I get here?"; } print map "$_\n", @output; #### $_ = "Hello there, people!"; @output = (); while (pos $_ <= length $_) { (push @output, "word: $1"), next if /\G(\w+)/gc; (push @output, "spaces"), next if /\G\s+/gc; (push @output, "punc: $1"), next if /\G(.)/gc; die "how did I get here?"; } print map "$_\n", @output;