Perl 5.40 Now Generally Available

Perl 5.40

Perl 5.40.0 was released on June 9, 2024, delivering a wealth of new features, optimizations and security fixes. Major highlights include:

  • New __CLASS__ Keyword, which provides a runtime-aware class reference.
  • A :reader attribute for field variables, which can simplify your code and enhance its readability.
  • The introduction of the ^^ logical xor operator, completing Perl’s set of logical operators.
  • Error handling with try/catch first introduced in Perl 5.34 is now finally considered stable.

Let’s take a look at each of them starting with:

The __CLASS__ keyword

Perl implemented Classes in its core libraries with version 5.38 by adding Object Oriented (OO) syntax similar to other OO programming languages. Consider the following example from Nikos Vaggalis’ blog:

use v5. 38;

use feature 'class';

class My::Example 1. 234 {

   field $x;


       $x = "Hello, world";


  method print_message {

     say $x;




The new __CLASS__ token can be invoked within a method in order to return the name of the class of the invoking instance, just like ref($self). But it can also be used in a field initializer to provide access to class methods before the instance is fully constructed. For example:

use feature 'class';

class Example1 {

     field $f = __CLASS__->default_f;

    sub default_f { 10 }


The :reader Attribute

When decorating a member variable, the :reader attribute automatically generates an accessor named after it. For example:

field $name :reader;

is equivalent to

field $name;

method name () { return $name; }

The ^^ operator

Rounding out the current set of && and || operators is the new “exclusive-or” operator, which can be used as follows:

$x ^^ $y and say "One of x or y is true, but not both";

Try/Catch Error Handling

Try/catch was first introduced way back in Perl 5.34, a version that is now EOL.  Try/catch blocks take the form:

use feature 'try';

try {

   . . .


catch ( $e ) {

  . . .


This is on par with most OO programming languages when it comes to structured exception handling. 

In addition to these key features, v5.40 also introduces a number of performance enhancements and speed optimizations to make processing faster for certain operations. To see all the new, optimized and enhanced features, as well as the fixes and improvements, read the PerlDelta docs.

Perl & ActiveState

Perl 5.40 is the latest stable release of Perl 5, now in its fourth decade. With its release, almost a year since last stable version (Perl 5.38) was released, ActiveState is making a number of changes to how Perl is offered on the ActiveState Platform, namely:

  • Perl v5.40.0 is now generally available starting today for all users.
  • Perl v5.38.2 is now the recommended version of Perl for all users (replacing Perl v5.36.3). This is the target version against which all popular packages will be built. 
    • This means that if you’re having issues trying to build a package against other Perl versions, you will likely have better success with v5.38.2.
  • Perl v5.34 has been removed from our Free Tier. Users on the ActiveState Platform’s Free Tier will no longer be able to create new projects using Perl v5.34, however, existing projects will continue to work, as usual.
    • Note that Perl v5.34 was released May 20, 2021 and ended active support on July 02, 2023. Critical security fixes became unavailable on May 20, 2024, however, ActiveState continues to provide extended/EOL support to customers that require an affordable commercial support option.

While Perl was one of the most popular programs for decades, it’s been declared prematurely dead repeatedly over the past few years. The truth lies somewhere in the middle:

  • Very few major Perl projects are being started today.
  • Perl still has a number of relevant uses today, primarily for text processing.

However, there are mountains of legacy Perl code in the enterprise that’s unlikely to be rewritten anytime soon, but will need to be maintained and in some cases improved. Perl 5.40 provides a great basis for this since you can now write cleaner, optimized code with better readability. 

ActiveState provides a virtual install of Perl by default, allowing you to try out Perl 5.40 without disrupting your current Perl installation. And if you’re tasked with maintaining multiple Perl projects, ActiveState provides the simplest way to work with multiple Perl projects at once without conflicts. 

The next major stable release of Perl should appear in the first half of 2025, and will be added to the ActiveState Platform shortly thereafter.

Next Steps

You can make a project based on Perl 5.40 by creating a free account (or signing into your existing account) on the ActiveState Platform. Just click the New Project Button and select Perl then version 5.40 to get started.

Recent Posts

Scroll to Top