in reply to regex word return
why answer is 1 without bracket ?
The match operator returns TRUE on success or FALSE on failure (1 or '') and since /\w/ matched it returns 1.
why answer is b with bracket?
A regular expression with capturing parentheses returns the contents of those capturing parentheses in list context so the first string that matches \w is returned.
It looks like you may want to use the /g (global) match option:
@a = $s =~ /\w/g;
|
|---|