([^ ]+) means match one or more characters which are not a space
([^\W]+ means match one or more characters which are not a-zA-Z0-9_
which is not exactly the same thing.
^ within square brackets means "not". Otherwise ^ means start of the string, and $ means the end of the string.
/^(Philip)/ matches Philip at the start of the string
[^xyz] matches anything which is not an x, a y or a z.
str = "John O'Smith-Jones"
str = str.replace(/^(\S+)\s+(\S+)$/,"$2 $1");
I expect Perl is the same.