Inflation can be a significant problem for investors in at least two ways. First, the rise in prices leads to increased costs and expenses for corporations, as well as decreased consumer spending, which harms businesses' financial results. Second, inflation reduces purchasing power over time. Fortunately, investing in stocks can help get around those issues.
Over the long run, equities have outpaced inflation, making them a good hedge against it. And some companies perform relatively well financially even in inflationary periods. However, it's crucial to invest in the right companies, preferably those whose businesses are well-equipped to withstand significant price rises and can also match, or even exceed, the performance of the broader market.
Let's consider two great examples: Vertex Pharmaceuticals (VRTX +2.32%) and Mastercard (MA +0.68%).
Image source: Getty Images.
1. Vertex Pharmaceuticals
Vertex Pharmaceuticals, a leading biotech company, can perform well despite inflation thanks to its pricing power, a characteristic many drugmakers possess. Medicines are granted patents that protect them from generic or biosimilar competition for a long time, allowing their makers to charge significantly higher prices than they would otherwise be able to. However, most therapies still have to compete with drugs that treat the same illnesses.
That's not the case here. Vertex's core cystic fibrosis (CF) franchise is the only game in town for patients with this rare genetic disease that affects internal organs, so the company has performed well over the past decade. Its revenue and earnings have generally grown steadily as it continues to make significant breakthroughs in CF.
VRTX Revenue (Quarterly) data by YCharts.
The biotech still has plenty of room to grow here. Although CF is rare, patients taking Vertex's medications typically need to take them regularly for life. That's not counting the thousands who are eligible for its current therapies but have yet to start treatment. So Vertex Pharmaceuticals should continue riding this wave for a while longer, especially since its most important medicines won't encounter patent cliffs until the second half of the next decade.

NASDAQ: VRTX
Key Data Points
In the meantime, the company is developing newer therapies. Vertex has launched Casgevy, a treatment for two rare blood diseases, and Journavx, a non-opioid oral therapy for the management of acute pain. And it has more exciting candidates in the pipeline, including zimislecel, a potential treatment for type 1 diabetes, and inaxaplin, a medicine for APOL-1-mediated kidney disease.
Vertex has encountered some clinical setbacks this year, so the stock has not performed well, but its prospects are attractive. The biotech could deliver market-beating returns over the medium term as it makes more headway into its core market, newer products gain traction, and it launches other brand-new medicines. Vertex Pharmaceuticals remains a great pick to help hedge against inflation.
2. Mastercard
Mastercard is a leading payment network company that most people recognize, because millions of cards in circulation are branded with its logo. The financial services specialist helps process card transactions by connecting merchants and banks through its network. Mastercard earns money through fees it charges for every transaction it helps process.
Since these fees are calculated as a percentage of the purchase amount, inflation results in higher revenue per transaction. True, the rise in prices can cool down consumer spending, which harms Mastercard's revenue growth. Overall, however, these two forces somewhat offset one another, and Mastercard is generally able to perform relatively well despite inflationary pressures.
And over the long run, the company can also outpace the broader market for at least two reasons.

NYSE: MA
Key Data Points
First, Mastercard has exceptional growth prospects. The company still estimates trillions of dollars' worth of cash and check transactions can be converted into digital ones. And although Mastercard has a smaller global market share than its larger rival Visa, it has greater exposure to international markets where credit card penetration is even lower; this presents explosive growth potential (even if that also comes with a bit more risk).
Second, Mastercard is an exceptional dividend stock. Don't let its 0.6% forward yield fool you. The company has increased its dividend by 300% over the past decade, while still boasting a highly conservative cash payout ratio of 18.1%, and has ample room to increase its dividend further. Reinvesting Mastercard's growing regular payout will help boost returns over the long run, lifting them even higher above those of broader equities.
