my ($shows, $allshows); for my $i ( 0 .. $#ids ) { $stmt = "SELECT * FROM shows WHERE type = 2 AND id = '$ids[$i]'"; $sth = $dbh->prepare($stmt); $sth->execute(); push @$allshows, $sth->fetchall_arrayref({}); }