Skip to main content

The Perl 5 language interpreter.

# To parse and execute a Perl script:
perl <script.pl>

# To check syntax errors on a Perl script:
perl -c <script.pl>

# To parse and execute a Perl statement:
perl -e <perl_statement>

# To run a Perl script in debug mode, using 'perldebug':
perl -d <script.pl>

# To edit all file lines [i]n-place with a specific replacement [e]xpression and save a file with a new extension:
perl -p -i'.<extension>' -e 's/<regular_expression>/<replacement>/g' <path/to/file>

# To run a multi-line replacement [e]xpression on a file, and save the result in a specific file:
perl -p -e 's/<foo\nbar>/<foobar>/g' <path/to/input_file> > <path/to/output_file>

# To run a regular [e]xpression on stdin, printing matching [l]ines:
cat <path/to/file> | perl -n -l -e 'print if /<regular_expression>/'

# To run a regular [e]xpression on stdin, printing only the first capture group for each matching [l]ine:
cat <path/to/file> | perl -n -l -e 'print $1 if /<before>(<regular_expression>)<after>/'