my $sql = "SELECT G.Region, G.Score FROM Gov_regions_scores_TEMP G, Region_lookup R WHERE R.String = ? AND RTRIM(R.Place) = RTRIM(G.Region) LIMIT 2"; my $sth = $dbh->prepare( $sql ); foreach ( @regions_A_array ) { $sth->execute( $_ ); for ( 1, 2 ) { my @regions_A = $sth->fetchrow_array; print OUTPUT "@regions_A\n"; } } $sth->finish();