perl — Perl interpreter
Development / Build / perl.html
The interpreter for Perl, a language strong at text processing.
Basic Information
| Command Name | perl |
|---|---|
| One-line Introduction | The interpreter for Perl, a language strong at text processing. |
| Provided by | Perl 5 |
| Official Documentation | https://perldoc.perl.org/ |
| Supported Operating Systems | Linux, macOS, BSD, Windows |
| Installation Status | Installed by default |
| Category | Build and compile (tags: Language toolchain (tags: perl, regex, text processing, cpan)) |
What is this command?
perl is an interpreter specialized in regular expressions and text transformation. -e runs inline code, while -n/-p make file-scanning one-liners practical.
CPAN offers a huge module ecosystem, but on production hosts pin dependencies via distribution packages or cpanm. For complex logic, prefer script files over one-liners.
What problems does it solve?
- Transforming logs or CSV with regular expressions
- Replacing patterns across many files
- Maintaining legacy Perl scripts
- System scripts that need powerful string handling
Key features
One-liners
Combine -e with -n/-p to process files while scanning.
- When to use: Quick log filtering or substitution
- What you get: Accomplishes repetitive processing with little code.
- Limitations: Complex regexes quickly become unreadable.
Regex handling
Freely combine substitution (s///) and matching (m//).
- When to use: Extracting fields from unstructured text
- What you get: Powerful pattern matching is available.
- Limitations: Greedy matching can produce unexpected results.
Module ecosystem
Extend functionality with CPAN modules.
- When to use: When higher-level features such as JSON or HTTP are needed
- What you get: Use tested modules instead of writing your own.
- Limitations: Dependency pinning and security updates must be managed.
Installation and usage
Check whether it is installed
perl -v
sudo apt install perl # Debian/Ubuntu sudo dnf install perl # Fedora
Real-world examples
Run a one-liner
Execute a short snippet immediately.
perl -e 'print join(",", 1..5), "\n"'
Pattern substitution
Read a file, replace a pattern and print the result.
perl -pe 's/ERROR/ERR/g' app.log | head
Extract fields
Pull only the needed values with a regex.
perl -ne 'print "$1\n" if /status=(\d{3})/' access.log | sort | uniq -c