in reply to typeglobs and filehandles

If you add
local *FH;
at the top of function foo, it will work.