Chapter 68. Basic Perl Anatomy

Chip Salzenberg

In Components of the Perl Distribution, I described the overall content and layout of the perl distribution. Now that the stage has been set, I’ll show how perl implements the Perl language, with occasional excursions into the standard library.

We’ll survey the major portions of perl and their functions. You’ll notice that the word “perl” isn’t always capitalized in this column. That’s because Larry Wall draws a distinction between “Perl” the language and perl the program—in theory, there could be other programs besides perl that implement Perl. Thus, this article is not about “the guts of Perl” but rather “the guts of perl.”

How Perl Works

Here’s a bird’s-eye view of how perl executes your Perl programs:

Lexical analysis

perl reads your program and breaks it down into basic syntactic elements, called tokens.


perl figures out the meaning of those tokens in that specific sequence.


perl builds an internal structure representing operations that, when executed, will perform the actions specified by your program.


perl steps through those operations and performs them, one by one.

Note that perl distinguishes Step 3from Step 4. The line is blurred by BEGIN {} blocks, which specify Perl code to be executed during the compilation phase-— before your program runs.

Step 3 settles one of the frequently asked questions about Perl: perl is a compiler, not an interpreter. Specifically, it’s a “load-and-go compiler.” Incidentally, current ...

Get Computer Science & Perl Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.