http://qs321.pair.com?node_id=11140502


in reply to Regex match for Any number of words?

There are several ways to do this. A rather short one is:
my $text = " THIS is a variable number of words, spaces and punctuat +ion. "; my @list = split /\W+/,$text;

So I'm splitting the text whenever I found one or more characters which are not words.

I don't know whether eliminating empty strings at the beginning and the end of the list is relevant, so I'm leaving this as an exercise to the reader (hint: grep $_,@list might not do what you want if you consider numbers as words).