Using my to declare the local variable in a subroutine
#!/usr/bin/perl -w $x = 10; print "before: $x\n"; change_global_not(); print "after: $x\n"; sub change_global_not { my $x = 20; print "in change_global_not(): $x\n"; }