my @data = (); my @final = (); while (!$client->timeout()) { my $stream = $client->get_data(); push(@data,$stream); } foreach (@data) { push(@final,munge($_)); #<-- push hash ref onto @final } sub munge { my %hash = (); #...create hash return \%hash; #<-- hash ref }