Perl Regular Expression Modifiers

Modifiers which can optionally follow the last slash (or delimiter) of a perl regular expression:
Modifier Meaning
c Continue
Do not reset position after failure to match.
Note: current position in string is associated with the string not the regex.
Different strings have different positions, which can be set or read independently.
e Evaluate
wraps an "eval{...}" around the resulting string
and the revaluated result is substituted for the matched substring.
Examples:
   $x = "A 39% usage";
   $x =~ s!(\d+)%!$1/100!e; $x is now "A 0.39 usage"
   $y = "cat in the hat";
   $y =~ s/(\w+)/reverse $1/ge; $y is now "tac ni eht tah"
i Ignore case
"/yes/i" is equivalent to "/[yY][eE][sS]/"
g Global
m Treat string as multiline; i.e. "^" matches beginning of strings or
after a newline, and "$" matches end of string or before a newline
(older perl used "$*", but this is deprecated)
o Substitute variables only once
s Treat string as single line; i.e. "." can also match a newline.
Can use other delimiters such as: s!!! s{}{} s{}// s'''
x Extend pattern's legibility by permitting whitespace and comments.
Ignore whitespace that is neither backslashed nor within a character class.
The "#" characters in an expression (outside a character class) introduce
a comment.

The global modifier, ".../g", allows the matching operator to match within a
string as many times as possible. In a scalar context, successive matches against
a string will have ".../g" jump from match to match, keeping track of position
in the string as it goes along. Use the "pos()" function to keep track:
   $x = "cat dog horse"; # 3 words
   while ($x =! /(\w+)/g) {
      print "Word is $1, ends at position", pos $x, "\n";
   }
which prints:
   Word is cat, ends at position 3
   Word is dog, ends at position 7
   Word is horse, ends at position 13
A failed match or changing the target string resets the position.
If you do not want the position reset after faulure to match, add the
".../c" modifier, as in "/regex/gc".
Note: pos() can also be used to set the current position.
Alternately, the modifiers "/i", "/m", "/s", and "/x" can be placed in the
regex by using: "(?i)", "(?m)", "(?s)", and "(?x"); e.g. "(?i)yes)/".