You are viewing the version of this documentation from Perl 5.38.1. View the latest version
$OLD_PERL_VERSION
$]

The revision, version, and subversion of the Perl interpreter, represented as a decimal of the form 5.XXXYYY, where XXX is the version / 1e3 and YYY is the subversion / 1e6. For example, Perl v5.10.1 would be "5.010001".

This variable can be used to determine whether the Perl interpreter executing a script is in the right range of versions:

warn "No PerlIO!\n" if "$]" < 5.008;

When comparing $], numeric comparison operators should be used, but the variable should be stringified first to avoid issues where its original numeric value is inaccurate.

See also the documentation of use VERSION and require VERSION for a convenient way to fail if the running Perl interpreter is too old.

See "$^V" for a representation of the Perl version as a version object, which allows more flexible string comparisons.

The main advantage of $] over $^V is that it works the same on any version of Perl. The disadvantages are that it can't easily be compared to versions in other formats (e.g. literal v-strings, "v1.2.3" or version objects) and numeric comparisons are subject to the binary floating point representation; it's good for numeric literal version checks and bad for comparing to a variable that hasn't been sanity-checked.

The $OLD_PERL_VERSION form was added in Perl v5.20.0 for historical reasons but its use is discouraged. (If your reason to use $] is to run code on old perls then referring to it as $OLD_PERL_VERSION would be self-defeating.)

Mnemonic: Is this version of perl in the right bracket?