Perl quick reference
Perl 5.40 essentials: scalars, arrays and hashes, control flow, subroutines with signatures, references, strings and regular expressions, input and files — and how a Perl program runs in Zerethon IDE.
Written for Perl 5.40. Examples that show an output were run in the Zerethon sandbox (Perl 5.40) on 2026-10-24.
Basics
-
Hello, World
The smallest Perl program,
use v5.40, and printing withsayandprint. -
Scalars, arrays and hashes
The three kinds of variable —
$scalar,@array,%hash—my,undef, and numbers vs strings. -
Conditions and loops
if/elsif/unless,forover a list or range,while, statement modifiers, andnext/last. -
Subroutines
Define subroutines with
suband signatures, default arguments, returning lists, the older@_style, and anonymous subs.
Data
-
Working with arrays and hashes
push,sort,mapandgrep, slices,exists,//for defaults, and counting with a hash. -
References and nested data
Build hashes of arrays and lists of hashes with references:
[...],{...},->and postfix dereference->@*. -
Strings and regular expressions
String functions,
printf, matching with=~, capture groups,/g, and substitution withs///r.
Input and files
-
Reading input (stdin)
Read what you type in the IDE's Input tab with
<STDIN>andchomp. -
Reading and writing files
Open project files with three-argument
openandor die, read line by line, and write temporary files under/tmp. -
Modules and several files
Put subs in a
.pmmodule, load it withuse libanduse, and use core modules such asList::Util.
In Zerethon IDE
-
Running Perl in Zerethon IDE
What Run does with your project, the time limit, input, tests, and what a run cannot do.
-
Common errors
What
Global symbol requires explicit package name,Use of uninitialized value,isn't numeric,Can't locateandstrict refsmean and how to fix them. -
Official documentation
Where to read more: perlintro, the function and operator references, the regex tutorial and perldiag.