foreach my $key (@keys) { # You are using 'RaiseError', right? $sth->execute($key); while (my @temp_columns = $sth->fetchrow_array) { push(@entries, \@temp_columns); } }