Identifier names like $sql_count_A_Ref_vs_Comp_B might be indicative of a deeper design problem. But a solution to the immediate problem presented could be:
foreach my $sql (
$sql_count_A_Ref_vs_Comp,
$sql_count_A_Ref_vs_Comp_B,
$sql_count_A_ref_vs_Comp_C,
$sql_count_A_Ref_vs_Comp_D
) {
my $sth = $dbh_B->prepare( $sql ) or die "Cannot prepare: " . $dbh
+_B->errstr();
$sth->execute() or die $sth->errstr;
}
This lets $sql stand in as an alias for each of those sql_count_A_blah_blah_blah variables. Then you just loop over them, repeating the same process for each.