#cat Example.pm package Example; use strict; use warnings; sub my_test{ print "output from sub\n"; print "package ",__PACKAGE__," spot debug!!\n" if $ENV{DEBUG_TEMP}; } 1; #cat test-env.pl use strict; use warnings; use lib '.'; use Example; Example::my_test(); # test without the var $ENV{DEBUG_TEMP} = 1; Example::my_test(); # test with the var #perl test-env.pl output from sub # output before var setting output from sub # two lines after var setting package Example spot debug!! # when the program exits, DEBUG_TEMP disappears #perl -I . -MExample -e "Example::my_test()" output from sub