Did you have something like this in mind?
#!/usr/bin/perl
use strict;
use warnings;
our $var = 'foo';
sub test {
my $var = 'bar';
print $main::var, "\n";
print "$var\n";
}
test();
Output:
foo
bar
Notes:
- You really shouldn't reuse variable names like this. As you have already discovered it makes debugging a lot more difficult and increases the likelihood of making mistakes.
- You should read up on 'our' to understand the full ramifications of using it (e.g. run perldoc -f our).