Pattern-Matching Operators
The following list defines Perl’s pattern-matching operators. Some of the operators have alternative “quoting” schemes and have a set of modifiers that can be placed directly after the operators to affect the match operation in some way.
m/pattern/gimosxeSearches a string for a pattern match. Modifiers are :
Modifier
Meaning
gMatch globally, i.e., find all occurrences.
iDo case-insensitive pattern matching.
mTreat string as multiple lines.
oCompile pattern only once.
sTreat string as single line.
xUse extended regular expressions.
If
/is the delimiter, then the initialmis optional. Withm, you can use any pair of non-alphanumeric, non-whitespace characters as delimiters.?pattern?This operator is just like the
m/pattern/search, except it matches only once.qr/pattern/imosxCreates a precompiled regular expression from
pattern, which can be passed around in variables and interpolated into other regular expressions. The modifiers are the same as those form//above.s/pattern/replacement/egimosxSearches a string for
patternand replaces any match with thereplacementtext. Returns the number of substitutions made, which can be more than one with the/gmodifier. Otherwise, it returns false (0). If no string is specified via the=~or!~operator, the$_variable is searched and modified. Modifiers are:Modifier
Meaning
eEvaluate the right side as an expression.
gReplace globally, i.e., all occurrences.
cgContinue search after
gfailed. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access