title: What magic in "our" or "use vars" satisfies "use strict qw(vars)"?
body: <p>I have working code, but I am trying to understand <em>why</em> it works. I am also trying to learn more about the internals of Perl 5 (<code>perlbrew</code>, <code>perl-5.26.1</code>, <code>Cygwin x64</code>).</p>
  
  <p>I know from <a href="http://perldoc.perl.org/perlvar.html" rel="nofollow noreferrer"><code>perlvar</code></a> and <a href="https://metacpan.org/source/SHAY/perl-5.26.1/lib/strict.pm" rel="nofollow noreferrer"><code>strict</code></a> that <code>use strict 'vars'</code> works by setting flags in <code>$^H</code>.  Perl then tests accesses to non-<code>::</code> variables based on those flags.  Somehow, both <code>our</code> and <code>use vars</code> mark variables so that they will pass the test.  How do they do so?</p>
  
  <p>For example:</p>
  
  <pre><code>perl -E 'package Foo;
      use strict "vars";
      use vars qw($foo);
      say $foo;'
  </code></pre>
  
  <p>runs fine (although it produces no output).  Based on <a href="https://metacpan.org/source/SHAY/perl-5.26.1/lib/vars.pm#L29" rel="nofollow noreferrer">the source for <code>use vars</code></a>, I tried this, which I thought would have the same effect:</p>
  
  <pre><code>perl -E 'package Foo;
      use strict "vars";
      my $sym = "Foo::foo";          # &lt;-- These two lines pulled straight
      *$sym = \$$sym;                # &lt;-- from the source for the vars pragma
      say $foo;'
  </code></pre>
  
  <p>However, it gave me an error: <code>Global symbol "$foo" requires explicit package name</code>.  I also tried <code>$sym = "::Foo:foo"</code> in the above, with the same result.</p>
  
  <p>I checked, and <code>$Foo::foo</code> is in the symbol table:</p>
  
  <pre><code>$ perl -E 'package Foo;
        use Data::Dumper;
        use strict "vars"; 
        my $sym = "Foo::foo";
        *$sym = \$$sym; 
        say Dumper(\%{"Foo::"});'    # &lt;-- Foo's symbol table
  
  Output: 
  $VAR1 = {
      'BEGIN'  =&gt; *Foo::BEGIN,
      'Dumper' =&gt; *Foo::Dumper,
      'foo'    =&gt; *Foo::foo          # &lt;-- yep, it's there
  };
  </code></pre>
  
  <p>What else is <code>use vars</code> doing that I'm missing?  Does <code>our</code> do the same, or something different?</p>
  
  <h3>Update</h3>
  
  <p>Here's an A/B based on <a href="https://stackoverflow.com/a/49739472/2877364">melpomene's answer</a>:</p>
  
  <pre><code>Fails                         Succeeds
  -------------------------     ----------------------------------
  package Foo;                  package Foo;
  use strict "vars";            use strict "vars";
  
                                BEGIN {
                                    package Bar;
  my $sym="Foo::foo";               my $sym = "Foo::foo";
  *$sym = \$$sym;                   *$sym = \$$sym;
                                }
  say $foo;                     say $foo;
  </code></pre>