Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 43 ยท Getting Started

What Is Perl?

Meet Perl, the practical scripting language built for text processing and glue code: its history, strengths, CPAN, the TMTOWTDI motto, and where Perl is used today.

Perl is a general-purpose programming language that is especially good at working with text. It was created by Larry Wall, who released the first version in 1987 to make report processing on Unix easier. The language grew quickly because it let one person write, in a few lines, jobs that needed long shell scripts or C programs before.

Perl is often called "the Swiss Army chainsaw of scripting languages", and the nickname fits. It is not the newest or the most fashionable language, but it is mature, fast to write, and still running in a lot of systems that move data around. In this tutorial you will learn modern Perl 5 (the current line is 5.42), written the way careful Perl programmers write it today.

Perl is not installed on this site, so real Perl code in these lessons is read-only. The interactive examples are honest stand-ins, written in Python or Bash, that show the same idea. Lesson Installing and Running Perl explains how to run Perl on your own computer.

A short history

From report tool to web glue

1987 Larry Wall releases Perl 1 for text reports.
1994 Perl 5 arrives with references, modules and objects.
1995 CPAN opens as a shared library of modules.
Late 1990s CGI scripts make Perl the glue of the early web.

Perl 5 is still developed, with a new release every year.

1 / 2

Perl 5, released in 1994, is the version people mean when they just say "Perl". It added references, which allow nested data, and a module system, which let the community share code. The Comprehensive Perl Archive Network, CPAN, followed in 1995 and is still one of the largest collections of reusable code in any language.

The language keeps evolving. Releases come out yearly, and each one stays compatible with old programs. Recent versions added subroutine signatures, a say function, a try/catch feature, and an experimental class feature for modern object-oriented code. Perl's strong compatibility promise is one reason programs written decades ago still run.

What Perl is good at

Perl's strengths all come from its history as a tool for getting jobs done.

  • Text processing. Regular expressions are built into the language syntax, not bolted on as a library. Matching, extracting and rewriting text takes very little code.
  • Glue code. Perl is happy to read a file, call another program, parse its output, query a database and print a report, all in one script.
  • CPAN. Tens of thousands of distributions cover databases, networking, dates, parsing, testing and more.
  • Quick scripts. You can write a throwaway tool in minutes, and Perl's one-liner mode replaces many sed and awk jobs.
  • Stability. Old code keeps working, which matters for systems that must run for years.

Here is a taste of what that looks like. This is read-only Perl, so you cannot run it here, but the output is shown below. It counts how often each word appears in a short sentence:

PERL
use v5.36;

my $text = "the cat and the hat and the bat";
my %count;
$count{$_}++ for split ' ', $text;

for my $word (sort keys %count) {
    say "$word: $count{$word}";
}
TEXT
and: 2
bat: 1
cat: 1
hat: 1
the: 3

Five lines of real work: split the text, count words in a hash, sort the keys, print. You will understand every symbol in this program by the end of the first few chapters.

TMTOWTDI

Perl's unofficial motto is TMTOWTDI, pronounced "tim-toady": "There's more than one way to do it." Perl rarely forces one style on you. You can loop with for, foreach, while, map, or a statement modifier, and each is idiomatic in the right place.

That freedom is a gift and a risk. It makes the language comfortable and expressive, but it also lets people write code that is hard for others to read. Good Perl style is the answer: use strict and warnings (see use strict and use warnings), name things clearly, and prefer the simple way unless there is a reason not to. This tutorial teaches the plain, readable ways first.

Python Stand-in: several ways to do the same job

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

All three give the same list. Perl offers the same variety: a for loop with push, or map { uc } grep { /^c/ } @words. You will meet both forms in List Functions and Sorting.

Perl as glue

Perl grew up next to the shell, and it still shines when the job is to connect tools. The Bash stand-in below does a classic "glue" task with ordinary Unix tools: take text, clean it, count and rank. In Perl you would do the whole pipeline inside one script, without launching four programs.

Bash Stand-in: a text pipeline in Bash

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

The shell version works, but each stage is a separate process and a separate mini-language. A Perl script keeps the data in hash variables and lets you add rules, such as skipping stop words or grouping by length, without rewriting the pipeline.

Perl 5 and Raku

You may read that "Perl 6" exists. That language was a long redesign project, and in 2019 it was renamed Raku so people would stop confusing it with Perl 5. Raku is a separate language with its own implementation and community, not a newer Perl you need to move to.

When someone says "Perl" today, they mean Perl 5. Perl 5 continues to ship new releases and is not deprecated. This tutorial is about Perl 5 only.

Where Perl is used today

Perl is rarely the first choice for a brand-new web startup, but it is far from gone. Typical uses include:

  • System administration and automation: log parsing, file migrations, deployment glue.
  • Data munging: cleaning, reformatting and converting text and CSV data.
  • Bioinformatics: many sequence-handling tools and pipelines were written in Perl.
  • Legacy and long-lived systems: banking, telecom and publishing platforms with decades of working Perl code.
  • Web applications: frameworks such as Mojolicious and Dancer2 are active and modern.
  • Developer tooling: Git helper scripts, test runners and build tools.

If you maintain servers or work with text-heavy data, knowing Perl pays off quickly, because you will find it already installed on most Linux and macOS machines.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Who created Perl, and what was its original purpose?

    Larry Wall released Perl in 1987 as a practical tool for processing text and reports on Unix systems.
  2. 2. What does CPAN provide?

    CPAN, the Comprehensive Perl Archive Network, hosts tens of thousands of reusable modules you can install and use.
  3. 3. What does the motto TMTOWTDI stand for?

    It means "There's more than one way to do it". Perl lets you choose between several valid styles.
  4. 4. What is the relationship between Perl 5 and Raku?

    Raku was called Perl 6 until 2019. It is a sibling language, and Perl 5 is still actively developed.

Summary

  • Perl is a mature scripting language created by Larry Wall in 1987, famous for text processing and glue code.
  • Perl 5 (1994) added references and modules; CPAN (1995) gives it a huge library of reusable code.
  • TMTOWTDI means there are many valid ways to write the same thing; readable style is up to you.
  • Raku (formerly Perl 6) is a different language; "Perl" today means Perl 5, which is still released every year.
  • Real Perl code on this site is read-only; the TryIts are Python or Bash stand-ins that show the same ideas.

Next, learn how to get Perl on your own machine in Installing and Running Perl.