#! /usr/bin/perl -T use strict; use warnings; use 5.020; use FindBin; use File::Spec; use Cwd qw( realpath ); use Scalar::Util qw( tainted ); our @LIB_DIRS; BEGIN { # build paths for different library directories # all are tainted because of $FindBin::Bin and realpath (which removes the /../ from the paths) # this script is located inside cgi-bin; and the lib directories are in parallel directories @LIB_DIRS = map { realpath( File::Spec->catdir( $FindBin::Bin, '..', $_ ) ) } qw( lib perl5lib stay-tainted ); # untaint dirs for ( @LIB_DIRS ) { if ( m|^([\w/]+)$|i ) { $_ = $1; } else { # better die here #die "$_ is an insecure path\n"; } } } use lib @LIB_DIRS; ### check for tainted directories say tainted($_). " $_" for @INC; # Now #use MyModule1; #use MyModule2;