"my" variable $k masks earlier declaration in same scope at a.pl line 6. #### use strict; my $k = 1; print "wanted: \$k = $k, got " . InvestigateValue() . "\n"; $k = 2;#modified print "wanted: \$k = $k, got " . InvestigateValue() . "\n"; sub InvestigateValue { return defined $k ? $k : 'undef'; }