Doesn't Perl include current directory in @INC by default?

Solution 1:

Perl doesn't search the current directory for modules or the script's directory for modules, at least not anymore. The current directory was removed from @INC in 5.26 for security reasons.

However, any code that relies on the current directory being in @INC was buggy far before 5.26. Code that did so, like yours, incorrectly used the current directory as a proxy for the script's directory. That assumption is often incorrect.

To tell Perl to look in the script's directory for modules, use the following:

use FindBin 1.51 qw( $RealBin );
use lib $RealBin;

or

use Cwd qw( abs_path );
use File::Basename qw( dirname );
use lib dirname(abs_path($0));

Solution 2:

Having . (the current directory) in @INC was removed in 5.26 for security reasons (CVE-2016-1238). Some Linux distributions have backported the change, so you might run into this problem even if you're using e.g. 5.24.

Solution 3:

Perl 5.26 removed having the current working directory in @INC as a security measure.

It's explained in the 5.26 perldelta notes.