One of the nation’s largest pharmacy benefits management companies will pay $38.5 million and limit its efforts to switch patients to costlier drugs, Attorney General Roy Cooper announced Thursday.

According to the complaint filed by Cooper, Caremark Rx, L.L.C. broke the law by encouraging doctors to switch patients to different brand name prescription drugs, claiming that doing so would save patients and/or health plans money.

The complaint alleges that Caremark failed to inform its clients that rebates collected by switching from one drug to another would be kept by Caremark and not passed on directly to the health plan.

As part of the settlement, Caremark must pay $38.5 million to 18 states, including $900,000 to North Carolina. Funds will go to benefit low-income, disabled or elderly consumers of prescription medications, promote lower drug costs for state residents, educate consumers about the cost differences among medications, or for similar purposes. Caremark will also pay up to $2.5 million to reimburse patients who were switched between certain drugs to control cholesterol.

Caremark will also be required to inform patients and their doctors what effect a drug switch will have on a patient’s co-payment, and to tell doctors about differences in side effects or efficacy between drugs and whether or not the company gets financial incentives for certain drug switches.

Caremark must reimburse patients for out-of-pocket health expenses related to switching drugs and notify patients and prescribers that reimbursement is available. Caremark will let patients know that they can decline to change drugs and will monitor the effects of drug switches.