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