for my $i ( 0 .. $#ids_to_match ) { my $stmt = "SELECT somedata FROM table WHERE id = $ids_to_match[$i]"; [execute, fetch, push into AoH] }