Ok, take your second test case, the one that doesn't work as you expect, and let's walk through it.
- Match "_x_y_" (I used _ to indicate a space character). One is found, and the pattern match position pointer is advanced to the 2nd 'x'.
- Look for another "_x_y_", but there isn't one, because you're already at position 'x', not position '_' (space).
What you may want is something like this:
m/\s$pattern(?=\s)/
This won't gobble the second space char.
| [reply] [d/l] [select] |