in reply to Regexp explanation

while ($string =~ /((\w|')+)/g) {
(\w|') matches either a word char or a single quote. Because the left paren here is the 2nd left paren in the regex, this captures into $2.

((\w|')+) matches one or more occurences of (\w|'). Because of the first left paren, this captures into $1. $2 will be the same as the last char of $1.

//g in a scalar context returns the next match, so the while will continue until all matches are found.

If you just want to add hypenated words, try this:

while ($string =~ /(([\w'-])+)/g) {...do something...}

Update: To get everything surrounded by whitespace, use

while ($string =~ /((\S)+)/g) {...do something...}
but this captures more than \w was doing. Or use split. Or see perlre.

-QM
--
Quantum Mechanics: The dreams stuff is made of