in reply to Returning and passing data to and from subroutines

my @data = shift;
That should probably be:
my @data = @_;

Your code only loads the @data array with one element.

See shift and perlsub.