100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Perl Cheat Sheet

Perl Cheat Sheet

Perl syntax, regular expressions, arrays, hashes, and text-processing idioms for scripting and command-line pattern-matching tasks.

1 PageIntermediateApr 10, 2026

Basic Syntax

Variables, control flow, and printing.

perl
#!/usr/bin/perluse strict;use warnings;my $age = 30;my $name = "Ada";my $pi = 3.14159;if ($age >= 18) {    print "$name is an adult\n";}for (my $i = 0; $i < 5; $i++) {    print "Count: $i\n";}

Regular Expressions

Pattern matching and substitution.

perl
my $text = "Contact: ada@example.com";if ($text =~ /(\w+)@(\w+)\.(\w+)/) {    print "User: $1, Domain: $2.$3\n";}(my $clean = $text) =~ s/[^a-zA-Z ]//g;   # substitutionmy @words = split /\s+/, $text;            # split on whitespacemy $joined = join(", ", @words);

Special Variables

Built-in variables used implicitly.

  • $_- default variable used implicitly by many operators (e.g. print, m//)
  • @_- array of arguments passed into a subroutine
  • $0- name of the currently executing script
  • @ARGV- command-line arguments passed to the script
  • %ENV- hash of environment variables
  • $@- error message from the last eval block

Hashes & Arrays

Perl's core aggregate data types.

perl
my @nums = (5, 3, 1, 4, 2);my @sorted = sort { $a <=> $b } @nums;   # numeric sortmy %ages = (Alice => 30, Bob => 25);$ages{Carol} = 28;for my $key (keys %ages) {    print "$key is $ages{$key}\n";}
Pro Tip

Always start scripts with `use strict; use warnings;` — they catch typos and unsafe symbolic references that would otherwise fail silently.

Was this cheat sheet helpful?

Explore Topics

#Perl#PerlCheatSheet#Programming#Intermediate#BasicSyntax#RegularExpressions#SpecialVariables#HashesArrays#DataStructures#CommandLine#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet