perl

The Perl 5 language interpreter

TLDR

Run a Perl script
$ perl [script.pl]
Execute a one-liner
$ perl -e 'print "Hello\n"'
In-place edit a file with substitution
$ perl -i -pe 's/old/new/g' [file]
In-place edit with backup (original saved as .bak)
$ perl -i.bak -pe 's/old/new/g' [file]
Print specific columns with autosplit
$ perl -ane 'print "$F[0]\n"' [file]
Check syntax without running
$ perl -c [script.pl]
Process input line by line (like sed/awk)
$ perl -ne 'print if /[pattern]/' [file]
Use a module from the command line
$ perl -MJSON -e 'print encode_json({key => "value"})'

SYNOPSIS

perl [options] [program] [arguments]

DESCRIPTION

perl is the Perl 5 language interpreter. Perl is a general-purpose programming language originally developed for text manipulation, combining features from C, sed, awk, and shell scripting.The language excels at text processing with powerful built-in regular expression support. It is widely used for system administration, web development, network programming, and data processing. The Comprehensive Perl Archive Network (CPAN) provides a vast repository of reusable modules.

PARAMETERS

PROGRAM

Perl script file to execute.
-e CODE
Execute the given code as a one-liner. Multiple -e flags are allowed.
-E CODE
Like -e but enables all optional features (say, state, etc.).
-n
Wrap code in a while(<>) loop, reading input line by line without printing.
-p
Like -n but also prints $_ after each iteration.
-i[EXT]
In-place edit files. If extension given, creates backup with that suffix.
-a
Turn on autosplit mode (used with -n or -p). Splits each line into @F.
-F PATTERN
Specify the split pattern for autosplit mode (default: whitespace).
-l
Enable automatic line-ending processing. Strips newlines on input, adds on output.
-0[OCTAL]
Specify input record separator as octal value. -0777 slurps entire files.
-w
Enable warnings (prefer `use warnings;` in scripts).
-W
Enable all warnings unconditionally.
-c
Syntax check only; do not execute the program.
-MMODULE
Load a module before executing (equivalent to `use MODULE`).
-T
Enable taint mode for security. Untrusted data cannot affect the system.
-S
Use PATH to find the script. Emulates #! on platforms that don't support it.
-d
Run the program under the debugger.
-v
Print version and configuration summary.

INSTALL

sudo apt install perl-base
sudo dnf install perl-base
sudo pacman -S perl
sudo apk add perl
sudo zypper install perl-base
brew install perl
nix profile install nixpkgs#perl

CAVEATS

Modern Perl scripts should use `use strict;` and `use warnings;` for safer code. The -i flag without an extension modifies files in place with no backup. CPAN modules can be installed with the cpan command.

HISTORY

Perl was created by Larry Wall in 1987 as a practical language for text manipulation and report generation. Perl 5, released in 1994, introduced major features including references, objects, and modules.

SEE ALSO

python(1), ruby(1), awk(1), sed(1), grep(1), cpan(1), perldoc(1)