in reply to Regex for Differentiating Underscore and Whitespace

Although it already correctly identify this string: $str = "TIP UPSTREAM"; as with underscore.
There is no underscore in "TIP UPSTREAM"! so your regex does not correctly identify your string. No wonder since you are not checking for underscores, but just for a space (and not even that due to the use of the x modifier).

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James