| Perl provides a rich set of regular-expression operators, constructs, and features, with more being added in each new release. Perl uses a Traditional NFA match engine. For an explanation of the rules behind an NFA engine, see Section 1.2. This reference covers Perl Version 5.8. Unicode features were introduced in 5.6, but did not stabilize until 5.8. Most other features work in Versions 5.004 and later. 1.3.1 Supported MetacharactersPerl supports the metacharacters and metasequences listed in Table 1-3 through Table 1-7. For expanded definitions of each metacharacter, see Section 1.2.1. Table 1-3. Character representations
 Table 1-4. Character classes and class-like constructs ( continued )
 Table 1-5. Anchors and zero-width tests
 Table 1-6. Comments and mode modifiers (continued)
 Table 1-7. Grouping, capturing, conditional, and control (continued)
 1.3.2 Regular Expression OperatorsPerl provides the built-in regular expression operators qr// , m// , and s/// , as well as the split function. Each operator accepts a regular expression pattern string that is run through string and variable interpolation and then compiled. Regular expressions are often delimited with the forward slash, but you can pick any non- alphanumeric , non-whitespace character. Here are some examples:  qr#...#       m!...!        m{...} s......    s[...][...]   s<...>/.../ A match delimited by slashes ( /.../ ) doesn't require a leading m : /.../ #same as m/.../ Using the single quote as a delimiter suppresses interpolation of variables and the constructs \N{ name } , \u , \l , \U , \L , \Q , \E . Normally these are interpolated before being passed to the regular expression engine. 
 qr/ PATTERN /ismxo Quote and compile PATTERN as a regular expression. The returned value may be used in a later pattern match or substitution. This saves time if the regular expression is going to be repeatedly interpolated. The match modes (or lack of), /ismxo , are locked in. 
 m/ PATTERN /imsxocg Match PATTERN against input string. In list context, returns a list of substrings matched by capturing parentheses, or else (1) for a successful match or ( ) for a failed match. In scalar context, returns 1 for success or "" for failure. /imsxo are optional mode modifiers. /cg are optional match modifiers. /g in scalar context causes the match to start from the end of the previous match. In list context, a /g match returns all matches or all captured substrings from all matches. A failed /g match will reset the match start to the beginning of the string unless the match is in combined /cg mode. 
 s/ PATTERN / REPLACEMENT /egimosx Match PATTERN in the input string and replace the match text with REPLACEMENT , returning the number of successes. /imosx are optional mode modifiers. /g substitutes all occurrences of PATTERN . Each /e causes an evaluation of REPLACEMENT as Perl code. 
 split / PATTERN /, EXPR , LIMIT split / PATTERN /, EXPR split / PATTERN / split Return a list of substrings surrounding matches of PATTERN in EXPR . If LIMIT , the list contains substrings surrounding the first LIMIT matches. The pattern argument is a match operator, so use m if you want alternate delimiters (e.g., split m{ PATTERN } ). The match permits the same modifiers as m{} . Table 1-8 lists the after-match variables. Table 1-8. After-match variables
 1.3.3 Unicode SupportPerl provides built-in support for Unicode 3.2, including full support in the \w , \d , \s , and \b metasequences. The following constructs respect the current locale if use locale is defined: case-insensitive ( i ) mode, \L , \l , \U , \u , \w , and \W . Perl supports the standard Unicode properties (see Table 1-3) as well as Perl-specific composite properties (see Table 1-9). Scripts and properties may have an Is prefix but do not require it. Blocks require an In prefix only if the block name conflicts with a script name. Table 1-9. Composite Unicode properties
 1.3.4 ExamplesExample 1-1. Simple match # Match Spider-Man, Spiderman, SPIDER-MAN, etc. my $dailybugle = "Spider-Man Menaces City!"; if ($dailybugle =~ m/spider[- ]?man/i) { do_something(  ); } Example 1-2. Match, capture group, and qr # Match dates formatted like MM/DD/YYYY, MM-DD-YY,... my $date  = "12/30/1969"; my $regex = qr!(\d\d)[-/](\d\d)[-/](\d\d(?:\d\d)?)!; if ($date =~ m/$regex/) {   print "Day=  ", ,         "Month=", ,         "Year= ", ; } Example 1-3. Simple substitution# Convert <br> to <br /> for XHTML compliance my $text = "Hello World! <br>"; $text =~ s#<br>#<br />#ig; Example 1-4. Harder substitution # urlify - turn URL's into HTML links $text = "Check the website, http://www.oreilly.com/catalog/repr."; $text =~      s{       \b                         # start at word boundary       (                          # capture to         (https?telnetgopherfilewaisftp) :                                   # resource and colon        [\w/#~:.?+=&%@!\-] +?     # one or more valid                                  # characters                                   # but take as little as                                  # possible       )       (?=                        # lookahead            [.:?\-] *                #  for possible punctuation         (?: [^\w/#~:.?+=&%@!\-]  #  invalid character            $ )                  #  or end of string       )      }{<a href=""></a>}igox; 1.3.5 Other Resources
   | 
