in reply to The weirdest problem with undef

As others have said, it looks like you're probably accessing two different sets of variables called @source and @destination. One is the lexical set that you are creating with the "my" call at the start of the loop and the other is the package variable set that you are setting in the "get_elements" call.

The two best pieces of advice that I can give you are:

  1. Stop relying on side-effects to populate global variables
  2. Turn on "use strict" and "use warnings" so you can see where you are unwittingly using package variables
--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg