Walgreens Boots Alliance Inc. is in advanced talks to buy Rite Aid Corp. in a deal that would unite the nation’s second- and third-largest drugstore chains.

A deal is expected to be announced Wednesday, according to people familiar with the matter. Rite Aid had a market value of more than $6 billion Monday afternoon, meaning that with a typical premium, a takeover deal could value the company at close to $10 billion. That doesn’t include its hefty debt load, which totaled $7.4 billion in August.

Rite Aid shares surged 38% to $8.38 after The Wall Street Journal reported the talks, while Walgreens rose 5% to $93.95.

A combination of the pharmacy chains would come amid waves of mergers in various corners of the health-care industry—from drug makers to hospital chains and insurers—as the federal health overhaul known as the Affordable Care Act and other developments pressure companies to lower costs, bulk up and increase leverage with suppliers.

Putting their drugstore networks together could yield cost savings at a time when the companies have been beset by drug-cost inflation. Other benefits could be derived from marrying Walgreens’ wholesale operation with Rite Aid.

Given their sizes, the deal would be expected to draw scrutiny from antitrust regulators, and big store and other divestitures could be required to win their blessing. Both companies have big store counts in states like California, New York and Massachusetts, while in others like Florida, Texas and Illinois, there is no overlap.

Rite Aid, based in Camp Hill, Pa., has about 4,600 drug stores in 31 states, according to the company’s website. Walgreens has roughly 8,200 U.S. stores while CVS Health Corp. has more than 7,800. In terms of market value, Rite Aid is much smaller than Walgreens and CVS, which both exceed $100 billion. Rite Aid had revenue in the fiscal year ended in February of $26.5 billion. Walgreens had revenue in the 12 months ended in August 2014 of $76.4 billion, while CVS had 2014 sales of $139.4 billion.

Rite Aid, like its rivals, has sought to broaden its offerings to boost sales.

The company has worked to expand its RediClinics, walk-in centers that can give flu shots and tend to ailments, and built a portfolio of 1,859 wellness stores, which offer organic food and natural personal-care options, and feature consultation rooms for discussions with pharmacists.

Rite Aid this year bought pharmacy-benefit manager Envision Pharmaceuticals Services, or EnvisionRx, for about $2 billion. Pharmacy-benefit managers process prescriptions for the groups that pay for drugs, usually insurance companies or corporations, and use their size to negotiate better deals with drug makers and pharmacies. They often operate mail-order pharmacies too.

In September, Rite Aid cut its earnings outlook in part because of costs associated with the EnvisionRX deal. That had contributed to a nearly 20% reduction in Rite Aid’s share price this year.

Walgreens, which is to report its results Wednesday, has more than 13,200 stores in 11 countries, according to its website. The company operates under the Walgreens and Duane Reade banners, and in the U.K. and elsewhere as Boots. It also has one of the largest pharmaceutical wholesale and distribution networks in the world. Walgreens was founded in 1901 when Charles R. Walgreen Sr. purchased the Chicago drugstore where he had worked as a pharmacist.

Last year, Walgreens acquired the part of European drugstore chain Alliance Boots GmbH that it didn’t already own. Under pressure from some shareholders, Deerfield, Ill.-based Walgreens considered using the acquisition to relocate overseas in a so-called “tax inversion”—a type of deal that is used to make a U.S. company more tax-efficient. Walgreens ultimately decided against relocating.

The company’s chief executive is Stefano Pessina, a septuagenarian Italian billionairewho took the role in July and served as executive chairman of Alliance Boots before the merger with Walgreens. Mr. Pessina hasn’t been shy about his desire to do big deals. “We can clearly see the need or the opportunity for horizontal and vertical consolidation in our industry,” he said on a conference call in July.

Mr. Pessina transformed a small family business into a European drug retailing and wholesaling powerhouse through a series of takeovers. In 2007, he took the company private in an $18.5 billion leveraged buyout with KKR & Co. At year-end KKR still owned 4.6% of Walgreens stock.

In 2013, AmerisourceBergen Corp. began an alliance with Walgreens and Alliance Boots before the two companies merged. Walgreens Boots Alliance now has a minority stake in the drug wholesaler, but doesn’t own its own pharmacy-benefit company like some of its rivals do.

A deal would come on the heels of a wave of consolidation among the biggest managed-care companies. If approved by regulators, they would shrink five major players in the U.S. to three. Aetna Inc. agreed to buy Humana Inc. for $34 billion in July. Just weeks later, Anthem Inc. agreed to buy Cigna Corp. for $48 billion.

Source: The Wall Street Journal