Perl Operator Precedense:


Operator Description
List Operators 
-> method call, dereference
++     -- autoincrement,-decrement
** exponetiation
!   ~   \ +- log. not, bit-not, reference operator, unary plus/minus
=~   !~ matches, not matches
*   /   %   x multiply, divide, modulus, string replicate
+   -   . plus, minus, string concatenate
<<   >> 
named unary operators like chomp,...
<   >   <=   >=   lt gt le ge 
==   !=   <=>   eq ne cmp 
& bit-and
|   ^ bit-or, bit-xor
&& log. and
|| log. or
..   ... ranges, noninclusive, inclusive
?: if-then-else
=   +=   -=   *= assignments
,   => comma, comma-arrow
not 
and 
or xor  

Alternative Delimiters:


qqDELIMITER text DELIMITER
example: qq/Dies ist ein Text/ oder qq#Dies ist ein "Text"#

Regular Expressions:

These characters have special meanings and have to be quoted:
.   *   ?   +   [   ]   (   )   {   }   ^   $   |   \
Metacharacter Description
^  , $ Beginning, End of String
(x|y) Alternative, x or y in String
[abc] Any one of the characters a,b or c
[^abc] Any character other than a,b,c
[a-z] Range, anything beween a and z
\d   \D a digit, a non digit
\w   \W a word-character, a non-word-character
\s   \S a whitespace, a non whitespace
\b the boundary between \w and \W
. any character exept newline
(abc) the phrase abc as a group
? preceding character or group my be present 0 or 1 times
+ preceding character or group my be present 1 or more times
* preceding character or group my be present 0 or more times
{x,y} preceding character or group present between x and y times
{x,} ... at least x times
{,y} ... at most y times
{x} ... exactly x times

Remark on greedyness:

The Perl regular expression engine is greedy by default:
It tries to match as much as possible. By applying a the ?-operator after a + or a *, greedyness is turned off.

Exampe:
In "This is a nice sentence." ([\w\s]*)\s([\w\s]*)\. will lead to "This is a nice" as first and "sentence" as second match
but ([\w\s]*?)\s([\w\s]*?). shows "This" as the first and "is a nice sentence" as the second match.
The non-greedy variant stops matching as soon as possible.

Other helpful things with regular expressions:

Grouping together without producing a backreference: /(blah)/ will produce a backreference to "blah" in $1 while /(?:blah)/ will not.

Look-ahaid: /help (?= me)/ will match help if it is followed by me, while /help (?! me)/ will match help if the following is not me
(?<=) and (?<!) are the look-behind counterparts

Backreferences: If you need a backreference before the match is complete, use \1 instead of $1

Special Character Definitions


    \   Quote the next metacharacter
    ^   Match the beginning of the line
    .   Match any character (except newline)
    $   Match the end of the line (or before newline at the end)
    |   Alternation
    ()  Grouping
    []  Character class

    *      Match 0 or more times
    +      Match 1 or more times
    ?      Match 1 or 0 times
    {n}    Match exactly n times
    {n,}   Match at least n times
    {n,m}  Match at least n but not more than m times

More Special Character Stuff

    \t          tab                   (HT, TAB)
    \n          newline               (LF, NL)
    \r          return                (CR)
    \f          form feed             (FF)
    \a          alarm (bell)          (BEL)
    \e          escape (think troff)  (ESC)
    \033        octal char (think of a PDP-11)
    \x1B        hex char
    \c[         control char
    \l          lowercase next char (think vi)
    \u          uppercase next char (think vi)
    \L          lowercase till \E (think vi)
    \U          uppercase till \E (think vi)
    \E          end case modification (think vi)
    \Q          quote (disable) pattern metacharacters till \E

Even More Special Characters

    \w  Match a "word" character (alphanumeric plus "_")
    \W  Match a non-word character
    \s  Match a whitespace character
    \S  Match a non-whitespace character
    \d  Match a digit character
    \D  Match a non-digit character
    \b  Match a word boundary
    \B  Match a non-(word boundary)
    \A  Match only at beginning of string
    \Z  Match only at end of string, or before newline at the end
    \z  Match only at end of string
    \G  Match only where previous m//g left off (works only with /g)