Brought to you by molecularsciences.org.
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
This publication may not be redistributed without this notice.

Perl Special Variables

Perl contains numerous variables that have a special meaning. Below is a list of many of them.

Variables

English Name

Description

$_ $ARG The default input and pattern-searching space
$& $MATCH The string matched by the last successful pattern match
$* $PREMATCH The string preceding whatever was matched by the last successful
pattern
$' $POSTMATCH The string following whatever was matched by the last successful
pattern match
$` $LAST_PAREN_MATCH The last bracket matched by the last search pattern
$+ $MULTILINE_NUMBER If set to 1, Perl 5+ does multi-line matching within a string
(the default is 0)
$. $INPUT_LINE_NUMBER The last current input line number from the last file handle
read (an explicit close on a file handle resets the line number)
$/ $INPUT_RECORD_SEPARATOR The input record separator (newline by default)
$| $OUTPUT_AUTOFLUSH If set to any nonzero value, forces a flush after every write or
print on the currently selected output device (the default is 0)
$, $OUTPUT_FIELD_SEPARATOR The output field separator for the print function
$\ $OUTPUT_RECORD_SEPARATOR The output record separator for the print function
$" $LIST_SEPARATOR The output list separator for the print function
$; $SUBSCRIPT_SEPARATOR The subscript separator for multidimensional array emulation
$# $OFMT The output format for printed numbers
$% $FORMAT_PAGE_NUMBER The current page number of the currently selected output file
handle
$= $FORMAT_LINES_PER_PAGE The current page length (printable lines) of the currently
selected output file handle

Further Reading