in reply to The weirdest problem with undef
How is get_elements filling @source and @destination if they're not being passed to it and they're lexical variables with visibility only in your loop?
It might help to see more of the code.
In Section
Seekers of Perl Wisdom