| Pattern Matching | Result | |
|---|---|---|
| $a =~ /pat/ | match | True if $a contains pattern |
| $a =~ s/p/r/ | substitution | Replace contents of p with r in $a |
| $a =~ tr/a-z/A-Z/ | translation | Translate to corresponding characters |
| Logical Operators | Result | |
|---|---|---|
| $a && $b | And | True if $a is true and $b is true |
| $a || $b | Or | $a if $a is true, otherwise $b |
| ! $a | Not | True if $a is not true |
| Arithmetic Operators | Result | |
|---|---|---|
| $a + $b | Add | Sum of $a and $b |
| $a - $b | Subtract | Difference of $a and $b |
| $a * $b | Multiply | Product of $a times $b |
| $a / $b | Divide | Quotient of $a divided by $b |
| $a % $b | Modulus | Remainder of $a divided by $b |
| $a ** $b | Exponentiate | $a to the power $b |
| ++$a,$a++ | Autoincrement | Add 1 to $a |
| --$a,$a-- | Autodecrement | Subtract 1 from $a |
| rand($a) | Random | A random number in range 0 .. $a |
| String Operators | Result | |
|---|---|---|
| $a . $b | Concatenation | Values of $a and $b as one long string |
| $a x $b | Repeat | Value of $a strung together $b times |
| substr($a,$o,$l) | Substring | Substring at offset $o of length $l |
| index($a,$b) | Index | Offset of string $b in string $a |
| Assignment Operators | Result | |
|---|---|---|
| $a = $b | Assign | $a gets the value of $b |
| $a += $b | Add to | Increase $a by $b |
| $a -= $b | Subtract from | Decrease $a by $b |
| $a .= $b | Append | Append string $b to $a |
| File Test Operators | Result | |
|---|---|---|
| -r $a | Readable | File name in $a is readable by effective uid |
| -w $a | Writable | Writable by effective uid |
| -x $a | Executable | Executable by effective uid |
| -o $a | Owned | Owned by effective uid |
| -R $a | Readable | Readable by real uid |
| -W $a | Writable | Writable by real uid |
| -X $a | Executable | Executable by real uid |
| -O $a | Owned | Owned by real uid |
| -e $a | Exists | File exists |
| -z $a | Non-zero size | File has non-zero size (returns size in bytes) |
| -s $a | Zero size | File has zero size |
| -f $a | Regular file | File is a regular file |
| -d $a | Directory | File is a directory |
| -l $a | Symbolic link | File is a symbolic link |
| -p $a | Named pipe | File is a named pipe (FIFO) |
| -S $a | Socket | File is a socket |
| -b $a | Block | File is a block special file |
| -c $a | Character | File is a character special file |
| -u $a | UID | File has setuid bit set |
| -g $a | GID | File has setgid bit set |
| -k $a | Sticky bit | File has sticky bit set |
| -T $a | Text file | File is a text file |
| -B $a | Binary | File is a binary file (opposite of -T) |
| -M $a | Modify | Age of file (at startup) in days since modification |
| -A $a | Last Access | Age of file (at startup) in days since last access |
| -C $a | Inode change | Age of file (at startup) in days since inode change |
