in reply to use of $_ is destroying @database ... why?
While I haven't tested this in detail, it would seem to me that your usage of while (<T>) in load_tbls is clobbering $_, which is aliased to an entry in @database. Thus, when the while loop exits, $_ is undefined (the exit condition).
In Section
Seekers of Perl Wisdom