Visit Modern Perl to download your own copy of this book or buy Modern Perl at Amazon.
Larry Wall released the first version of Perl in 1987. The language grew from its niche as a tool for system administrators who needed something more powerful than shell scripting and easier to use than C programming into a general-purpose programming language. Perl has a solid history of pragmatism and, in recent years, a disciplined approach to enhancement and backwards compatibility.

Over Perl's long history—Perl 5 has been continually refined over the past twenty years—our understanding of what makes great Perl programs has changed. While you can write productive programs which never take advantage of all the language has to offer, the global Perl community has invented, borrowed, enhanced, and polished ideas and made them available to anyone willing to learn them.

Modern Perl is a mindset. It's an approach to writing great software with the Perl programming language. It's how effective Perl programmers write powerful, maintainable, scalable, concise, and excellent code. It takes advantage of Perl's extensive library of free software (the CPAN) and language features designed to multiply your productivity.

You'll benefit most from this book if you have some experience with Perl or another programming language already. If you're comfortable writing and executing programs (and happy to consult the documentation when it's mentioned), you'll get the most from this book.

Running Modern Perl

The Modern::Perl module from the CPAN (The CPAN) allows Perl to warn you of typos and other potential problems. It also enables new features introduced in modern Perl releases. Unless otherwise mentioned, all of the code snippets in this book assume you've started with this basic program skeleton:

    #!/usr/bin/env perl

    use Modern::Perl '2015';
    use autodie;

If you don't have Modern::Perl installed, you could write instead:

    #!/usr/bin/env perl

    use 5.016;      # implies "use strict;"
    use warnings;
    use autodie;

Some examples use testing functions such as ok(), like(), and is() (Testing). The skeleton for these examples is:

    #!/usr/bin/env perl

    use Modern::Perl;
    use Test::More;

    # example code here


At the time of writing, the current stable major Perl release is Perl 5.22. If you're using an older version of Perl, you may not be able to run all of the examples in this book unmodified. The examples in this book work best with Perl 5.16.0 or newer, though we recommend at least Perl 5.20. While the term "Modern Perl" has traditionally referred to any version of Perl from 5.10.1, the language has improved dramatically over the past several years.

Though Perl comes pre-installed on many operating systems, you may need to install a more modern version. Windows users, download Strawberry Perl from or ActivePerl from Users of other operating systems with Perl already installed (and a C compiler and the other development tools), start by installing the CPAN module App::perlbrew

perlbrew manages multiple Perl installations, so that you can switch between versions for testing and deployment. You can also install CPAN modules in your home directory without affecting the system installation. If you've ever had to beg a system administrator for permission to install software, you'll appreciate this.


This book would not have been possible without questions, comments, suggestions, advice, wisdom, and encouragement from many, many people. In particular, the author thanks this edition's tech reviewers Andy Lester, Sean Lindsay, and Mohsen Jokar as well as Michael Swaine, editor of this edition. Contributors to this and previous editions include:

John SJ Anderson, Peter Aronoff, Lee Aylward, Alex Balhatchet, Nitesh Bezzala, Ævar Arnfjörð Bjarmason, Matthias Bloch, John Bokma, Géraud CONTINSOUZAS, Vasily Chekalkin, Dmitry Chestnykh, E. Choroba, Tom Christiansen, Anneli Cuss, Paulo Custodio, Steve Dickinson, Kurt Edmiston, David Farrell, Felipe, Shlomi Fish, Jeremiah Foster, Mark Fowler, John Gabriele, Nathan Glenn, Kevin Granade, Andrew Grangaard, Bruce Gray, Ask Bjørn Hansen, Tim Heaney, Graeme Hewson, Robert Hicks, Michael Hicks, Michael Hind, Mark Hindess, Yary Hluchan, Daniel Holz, Mike Huffman, Gary H. Jones II, Curtis Jewell, Mohammed Arafat Kamaal, James E Keenan, Kirk Kimmel, Graham Knop, Yuval Kogman, Jan Krynicky, Michael Lang, Jeff Lavallee, Moritz Lenz, Andy Lester, Jean-Baptiste Mazon, Josh McAdams, Gareth McCaughan, John McNamara, Shawn M Moore, Alex Muntada, Carl Mäsak, Chris Niswander, Nelo Onyiah, Chas. Owens, ww from PerlMonks, Matt Pettis, Jess Robinson, Dave Rolsky, Gabrielle Roth, Grzegorz Rożniecki, Jean-Pierre Rupp, Eduardo Santiago, Andrew Savige, Lorne Schachter, Alex Schroeder, Steve Schulze, Dan Scott, Alex-ander Scott-Johns, Phillip Smith, Christopher E. Stith, Mark A. Stratman, Bryan Summersett, Audrey Tang, Scott Thomson, Ben Tilly, Ruud H. G. van Tol, Sam Vilain, Larry Wall, Lewis Wall, Paul Waring, Colin Wetherbee, Frank Wiegand, Doug Wilson, Sawyer X, David Yingling, Marko Zagozen, Ahmad M. Zawawi, harleypig, hbm, and sunnavy.

Any remaining errors are the fault of the stubborn author.

to the index