Est. 1987 Intermediate

Perl

A highly capable, feature-rich programming language with over 35 years of development, known for text processing and system administration.

Created by Larry Wall

Paradigm Multi-paradigm: Procedural, Object-Oriented, Functional
Typing Dynamic, Weak
First Appeared 1987
Latest Version Perl 5.40.0 (2024)

Perl is a high-level, general-purpose programming language originally developed for text manipulation but now used for a wide range of tasks including system administration, web development, network programming, and bioinformatics. Its motto is “There’s more than one way to do it” (TMTOWTDI), reflecting its philosophy of giving programmers freedom and flexibility.

History & Origins

Larry Wall created Perl in 1987 while working at Unisys. He wanted a language that was more powerful than shell scripting but more accessible than C. The name “Perl” was chosen because Wall wanted a short name with positive connotations (he considered “Gloria” after his wife, and “Pearl” before discovering an existing language with that name).

Perl borrowed the best features from several languages:

  • C for syntax and data structures
  • sed and AWK for text processing
  • Shell for system interaction
  • Lisp for lists and higher-order programming

The Camel Book Era

The 1991 publication of “Programming Perl” by Larry Wall and Randal Schwartz (featuring a camel on the cover) became the definitive reference and helped establish Perl as a serious language. The O’Reilly camel remains the unofficial mascot of Perl.

Key Features

Regular Expressions

Perl’s regex implementation is so influential that “Perl-compatible regular expressions” (PCRE) became a standard used by other languages:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Find all email addresses in text
my @emails = $text =~ /[\w.+-]+@[\w.-]+\.\w+/g;

# Replace all occurrences
$text =~ s/foo/bar/g;

# Match with capture groups
if ($line =~ /^(\w+):\s*(.*)/) {
    my ($key, $value) = ($1, $2);
}

Context Sensitivity

Perl understands context—the same expression can behave differently in scalar vs. list context:

1
2
3
4
5
my @array = (1, 2, 3, 4, 5);

my $count = @array;      # Scalar context: 5 (count of elements)
my @copy = @array;       # List context: copies all elements
my ($first) = @array;    # List context: extracts first element

CPAN - The Comprehensive Perl Archive Network

CPAN is one of the oldest and largest repositories of reusable code modules. With over 200,000 modules, there’s likely a module for almost any task:

1
2
3
4
5
use LWP::Simple;           # HTTP requests
use DBI;                   # Database connectivity
use JSON;                  # JSON parsing
use DateTime;              # Date/time handling
use Mojolicious;           # Modern web framework

Sigils

Perl uses sigils (symbols) to indicate variable types:

1
2
3
4
$scalar = "single value";    # Scalar ($ = single)
@array = (1, 2, 3);          # Array (@ = "at" = array)
%hash = (key => "value");    # Hash (% looks like key/value)
&subroutine();               # Subroutine (& = ampersand)

Perl vs. Other Scripting Languages

FeaturePerlPythonRuby
First Released198719911995
TypingDynamicDynamicDynamic
PhilosophyTMTOWTDIOne obvious wayDeveloper happiness
RegexBuilt-in, powerfulModule (re)Built-in, Ruby-flavored
OOPOptional, flexibleStrongEverything is an object
SigilsYes ($, @, %)NoNo
CPAN/PyPI/Gems~200K modules~450K packages~170K gems

Modern Perl

Perl has evolved significantly since its early days. Modern Perl (5.10+) includes:

The say Function

1
2
use feature 'say';
say "Hello, World!";  # Automatically adds newline

Defined-or Operator

1
my $value = $hash{key} // "default";  # Use default if undefined

Smart Matching and Given/When

1
2
3
4
5
6
use feature 'switch';
given ($value) {
    when (/^\d+$/) { say "It's a number" }
    when ('foo')   { say "It's foo" }
    default        { say "Something else" }
}

Object-Oriented Perl with Moose/Moo

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
package Person;
use Moo;

has 'name' => (is => 'ro', required => 1);
has 'age'  => (is => 'rw', default => 0);

sub greet {
    my $self = shift;
    say "Hello, I'm " . $self->name;
}

Perl 5 vs. Raku (Perl 6)

In 2000, Larry Wall announced Perl 6 as a complete redesign of the language. After 19 years of development, Perl 6 was renamed to “Raku” in 2019 to clarify that it’s a separate language, not a replacement for Perl 5.

AspectPerl 5Raku
StatusActively maintainedActively developed
CompatibilityBackward compatibleNew language
SigilsType-based (@, %, $)Container-based
OOPBuilt-in + CPAN (Moose)Native, gradual typing
ConcurrencyThreads, async modulesBuilt-in promises, channels

Both languages continue to be developed independently.

Why Perl Today?

Despite newer alternatives, Perl remains relevant for:

  1. Text Processing: Still unmatched for complex regex operations
  2. Legacy Systems: Billions of lines of Perl code in production
  3. System Administration: Quick scripts for Unix/Linux tasks
  4. Bioinformatics: BioPerl is widely used in genomics
  5. CPAN: Mature, tested modules for nearly everything
  6. One-liners: Perfect for command-line text manipulation

Perl may not be the trendy choice, but it remains a practical, powerful tool for programmers who need to get things done.

Timeline

1987
Perl 1.0 released by Larry Wall as a Unix scripting language combining features of C, sed, awk, and shell
1988
Perl 2.0 introduces a better regex engine
1989
Perl 3.0 adds binary data handling capabilities
1991
Perl 4.0 released alongside the 'Programming Perl' book (the Camel Book)
1994
Perl 5.0 introduces references, modules, objects, and the Comprehensive Perl Archive Network (CPAN)
2000
Perl 6 development announced (later renamed to Raku), remaining a separate language
2010
Perl 5.12 introduces the 'say' function and pluggable keywords
2020
Perl 7 announced as the successor to Perl 5, enabling modern defaults
2024
Perl 5.40.0 released with continued active development

Notable Uses & Legacy

Amazon

Early Amazon.com was famously built with Perl; it still powers some internal tools and legacy systems.

Booking.com

One of the largest Perl codebases in the world, handling millions of hotel bookings daily.

DuckDuckGo

The privacy-focused search engine uses Perl for its backend and Instant Answers platform.

CPAN

The Comprehensive Perl Archive Network hosts over 200,000 modules for nearly any programming task.

Bioinformatics

BioPerl and related tools are widely used for DNA/protein sequence analysis in genomics research.

System Administration

Perl remains a staple for sysadmins automating Unix/Linux tasks, log parsing, and text processing.

Language Influence

Influenced By

C shell AWK sed Lisp BASIC

Influenced

PHP Python Ruby JavaScript Raku

Running Today

Run examples using the official Docker image:

docker pull perl:5.40-slim

Example usage:

docker run --rm -v $(pwd):/app -w /app perl:5.40-slim perl hello.pl

Topics Covered

Last updated: