Regular Expressions   «Prev  Next»
Lesson 7Substitution modifiers
ObjectiveUse the s// operator and appropriate modifiers to replace one element with another in a file.

Perl Substitution Modifiers

As with the m// operator, the s// operator also allows the use of modifiers:
Modifier Meaning
e evaluate the right side as an expression
Perl g-Modifier replace globally; in other words, all occurrences
i do case-insensitive pattern matching
m treat the string as multiple lines
o only compile the pattern once
s treat the string as a single line
x use pretty-printing extensions


The rest of the modifiers work the same as in the m// operator.
This module contains a "Pattern-matching modifiers" lesson and provides an explanation of the m// operator.

Perl s Operator - Exercise

Click the Exercise link below to write a program that uses the s// operator to replace all occurrences of one element in a file with another.
Perl s Operator - Exercise