By main section, you mean 'code not in subroutines', right? As you've discovered, Perl considers subroutines to be part of the block in which they were defined, so they have access to all the lexical variables of that block.
If you want to limit the scope of a lexical variable, you need to declare it inside a block, like this:
#!/usr/bin/perl -w
use strict;
sub foo();
# main:
{
my $bar = "I can see you";
&foo;
}
sub foo()
{
print "inside foo: $bar\n";
return(0);
}
With use strict, that code doesn't compile, because the $bar in foo() hasn't been declared, which is the effect you want.