use strict; use warnings; main(); main(); main(); sub main { my $foo = 5; print "Content-type: text/plain\n"; print "Content-disposition: inline; filename=foo.txt\n\n"; printf "Package: %s\n", __PACKAGE__; printf "[%s] Before: %s\n", $$, $foo; badness(5, $foo); # <----- change here printf "[%s] After: %s\n", $$, $foo; } sub badness { my $val = shift; our $foo; # <----- clever trick here(*) local *foo = \shift; # <- printf "[%s] badness: %s\n", $$, $foo; $foo += $val; }