$_ = "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;