in reply to Undef becomes hash reference somehow

This is not directly related with the autovivication issue you're experiencing, but please note that your program would not even compile using the following:
use strict; use warnings;
because $foo and $bar haven't been properly declared.

You should really use these pragmas for all your programs, except possibly one-liners. They let the compiler help you preventing many mistakes.