in fact, your code shouldn't be some thing like
my $pattern = qr{ab[crdnfqm]def};
if $string =~ m{ ($pattern) };
....
which doesn't find all strings with the pattern.
That is perhaps because the regex m{ ($pattern) } (which lacks the /x regex modifier) requires a space before and after $pattern in order to match.
I don't understand trailing xms at the end of pattern.
These are regex modifiers. The /x modifier makes the regex compiler ignore whitepace (for improved readability). The /m and /s modifiers control the behavior of, respectively, the ^ $ (string end) and . (dot) metacharacter operators. I have adopted the best practice recommended by TheDamian of always (well, almost always) including these modifiers in every qr// m// s/// regex I write. The reason for this is to improve regex readability (/x) and to make explicit the behavior of the ^ $ . operators (/ms).
Please see perlre, perlrequick, and perlretut.
In reply to Re^5: search of a string in another string with 1 wildcard
by AnomalousMonk
in thread search of a string in another string with 1 wildcard
by carolw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |