http://www.perlmonks.org?node_id=1005860


in reply to Re^3: What is the scope of $_?
in thread What is the scope of $_?

So when the foreach loop finishes it restores the undef value to $_. Thanks.