Keeping things local that should be local is a good housekeeping practice.
Technically speaking, using local (my) variables arises from the need of eliminating namespace clashes, but the fact is it has a somewhat unrelated purpose. That is, to make sure the scope of a variable solely depends on the lexical scope only. So you can tell the scope of the variable directly by looking within the current block and nowhere else. Subroutines invoked from within this block will not see the variable. so,
Code:
{ # BLOCK 1
my $var = 10;
{ # BLOCK 2
local $var2 = 100;
&mysub;
print "\$var = $var\n"; # (1)
print "\$var2 = $var2\n"; # (2)
}
$var += 10;
print "\$var = $var\n"; # (3)
print "\$var2 = $var2\n"; # (4)
}
&mysub;
print "\$var = $var\n"; # (5)
print "\$var2 = $var2\n"; # (6)
sub mysub {
$var += 2;
$var2 += 2;
}