for my $i ( 0 .. $#$proj ) { my $time = $dbh->selectall_arrayref($stmt, {Slice => {}}, $project_id); my @users; # Create a new array every pass through the loop. for my $j ( 0 .. $#$time ) { push @users, $time->[$j]; } $proj->[$i]{'users'} = \@users; } #### for my $i ( 0 .. $#$proj ) { my $time = $dbh->selectall_arrayref($stmt, {Slice => {}}, $project_id); $proj->[$i]{'users'} = $time; }