# perldoc > perl

---
type: CommandReference
command: perl
mode: man
section: "1"
source: man-pages
---

## Quick Reference
- `perl -e 'print "Hello, World!\n"'` — Execute a one-line program.
- `perl -ne 'print if /pattern/'` — Print lines matching a pattern.
- `perl -pe 's/foo/bar/g'` — Replace `foo` with `bar` on every line.
- `perl -i -pe 's/old/new/' file.txt` — Edit file in-place with a substitution.
- `perl -c script.pl` — Check syntax only.
- `perl -d script.pl` — Run under the debugger.
- `perl -V` — Show configuration summary.
- `perl -Mstrict -Mwarnings -e '...'` — Enable strict and warnings for one-liners.

## Name
Perl 5 language interpreter — Practical Extraction and Report Language (or Pathologically Eclectic Rubbish Lister).

## Synopsis
shell
perl [ -sTtuUWX ] [ -hv ] [ -V[:configvar] ]
     [ -cw ] [ -d[t][:debugger] ] [ -D[number/list] ]
     [ -pna ] [ -Fpattern ] [ -l[octal] ] [ -0[octal/hex] ]
     [ -Idir ] [ -m[-]module ] [ -M[-]'module...' ] [ -f ]
     [ -C [number/list] ] [ -S ] [ -x[dir] ] [ -i[extension] ]
     [ [-e|-E] 'command' ] [ -- ] [ programfile ] [ argument ]...
## Options
### Program Execution
- `-e 'command'` — Execute a single line of Perl code.
- `-E 'command'` — Like `-e` but enables all optional features.
- `-n` — Wrap code in `while (<>) { ... }` loop (process input line-by-line).
- `-p` — Like `-n` but also prints each line after processing.
- `-a` — Autosplit mode (splits `$_` into `@F`) when used with `-n` or `-p`.
- `-Fpattern` — Split pattern for `-a` (default whitespace).
- `-l[octal]` — Enable line‑ending processing; sets `$\` and chomps.

### Input/Output
- `-i[extension]` — Edit files in-place; backup files if extension given.
- `-0[octal/hex]` — Set input record separator (`$/`) to given character.

### Debugging and Safety
- `-c` — Check syntax only, do not execute.
- `-d[:debugger]` — Run under the debugger (default `perl5db.pl`).
- `-w` — Enable warnings globally (prefer `use warnings` pragma).
- `-W` — Force all warnings (overrides `no warnings`).
- `-X` — Disable all warnings.
- `-t` — Taint warnings (like `-T` but only warns).
- `-T` — Enable taint mode for security.
- `-U` — Allow unsafe operations (supersedes taint restrictions).

### Module Handling
- `-Idir` — Add directory to `@INC` include path.
- `-Mmodule` — Import module before executing the program.
- `-mmodule` — Like `-M` but does not import symbols.
- `-f` — Disable execution of `$Config{sitelib}/sitecustomize.pl`.

### Configuration and Information
- `-v` — Print version and exit.
- `-V[:configvar]` — Print configuration summary; optional variable name.
- `-h` — Print help summary.

### Miscellaneous
- `-s` — Enable rudimentary switch parsing from command line.
- `-S` — Search `PATH` for the script.
- `-x[dir]` — Extract script from mail/news/post; optional directory to `chdir`.
- `-C [number/list]` — Control Unicode and locale features.

## Examples
### One‑liner to print matching lines
shell
perl -ne 'print if /error/' logfile
### Search and replace in-place
shell
perl -i.bak -pe 's/foo/bar/g' *.txt
### Syntax check
shell
perl -c myscript.pl
### Debug a script
shell
perl -d myscript.pl
### Execute with strict and warnings
shell
perl -Mstrict -Mwarnings -e 'my $x = 42; print $x'
## Environment
See `perlrun` for a complete list of environment variables affecting Perl behaviour.

## See Also
- [perldoc](https://perldoc.perl.org/) — The primary Perl documentation browser.
- [perlintro](https://perldoc.perl.org/perlintro) — Introduction for beginners.
- [perlrun](https://perldoc.perl.org/perlrun) — Execution and options.
- [perlfunc](https://perldoc.perl.org/perlfunc) — Built-in functions.
- [perlvar](https://perldoc.perl.org/perlvar) — Predefined variables.
- [perlre](https://perldoc.perl.org/perlre) — Regular expressions.
- [perldiag](https://perldoc.perl.org/perldiag) — Diagnostic messages.
- [perlsec](https://perldoc.perl.org/perlsec) — Security.
- [perlport](https://perldoc.perl.org/perlport) — Portability.
- [perlstyle](https://perldoc.perl.org/perlstyle) — Style guide.
- [perlfaq](https://perldoc.perl.org/perlfaq) — Frequently asked questions.
- [https://www.perl.org/](https://www.perl.org/) — The Perl homepage.
- [https://www.cpan.org/](https://www.cpan.org/) — Comprehensive Perl Archive Network.

## Diagnostics
- Use `use strict;` to enforce variable declarations and catch common mistakes.
- Use `use warnings;` (or `-w` switch) to enable compiler warnings.
- The `use diagnostics;` pragma expands terse warnings into explanatory text.
- Compilation errors include the line number and the next token or token type.
- See `perldiag` for a complete list of diagnostic messages.

## Bugs
- `use warnings` is not mandatory; behaviour may vary without it.
- Perl relies on the system’s `atof()`, `stdio`, and other C library functions.
- Variable names are limited to 251 characters; diagnostic line numbers are stored as short integers (max 65535).
- Report bugs at [https://github.com/Perl/perl5/issues](https://github.com/Perl/perl5/issues) with full configuration output (`perl -V`).

## Notes
- Motto: *There's more than one way to do it.*
- The three principal programmer virtues: Laziness, Impatience, Hubris.

## Author
Larry Wall <larry@wall.org> and many contributors.

## Files
- `@INC` — Perl library search path (see `perlvar`).