WALGREENS has racked up an amazing track record over the past 30 years. Now, as it confronts some scary new rivals, the drug chain is going to find out if it's really built to last.

(FORTUNE Magazine) – WALGREENS MAY BE THE GREATEST COMPANY you've never met. Oh, sure, you're aware of Walgreens-with its 4,798 drugstores coast to coast serving four million customers a day, how could you not be? But Walgreens is such a low-key company in such a mundane business-its executives hate being the subject of articles like this one; its headquarters, in Deerfield, Ill., looks as if it was decorated roughly around the time of the Nixon administration-that it's easy to miss the fact that this 104-year-old chain has racked up one of the most impressive track records in corporate America.

Walgreens is the only FORTUNE 500 company other than Wal-Mart to have increased both sales and earnings every year for the past 30 years. Its share of the $221 billion prescription-drug market is 14% and growing. Between the end of 1975 and 2000, its shareholder returns exceeded GE's and Intel's. The stock peaked in 2000 and sputtered for a couple of years, but WAG consistently outperformed the S&P 500, and at its current level of around $46 a share, it has surpassed its previous peak. "The really interesting thing," says Jim Collins, the author and management guru, "is how something so dull could produce such extraordinarily exciting results. It's almost an enigma." Collins was impressed enough with Walgreens to make it one of the prime specimens in Good to Great, his 2001 bestseller that explored how undistinguished companies very occasionally morph into superstars. No wonder Wal-Mart CEO Lee Scott recently said that Walgreens "may be as good a competitor as we've got."

But as they say with mutual funds, past performance is no guarantee of future results, and Walgreens happens to be in the middle of a vicious multifront battle. First, there's Walgreens' biggest traditional rival, CVS, which has been expanding rapidly-it recently acquired 1,268 Eckerds to push its total store count to 5,415. Scarier still are the supermarkets and mass-merchandisers that have been moving emphatically into the pharmacy business. Wal-Mart, which already has 3,144 stores with pharmacies, is testing 24-hour pharmacies and offers eye exams in many stores. The most dangerous threat of all-and one to which, as we'll see, Walgreens was late to respond-is the rise of low-cost mail-order prescriptions, which represents a profound shift in the way Americans buy their medicines. "They are getting it from all sides," says Sandy Skrovan, vice president of Retail Forward, a consulting firm in Columbus.

So it's crunch time for Walgreens. And here's the question: Does this company have another big run left in it?

BEFORE GETTING TOO DEEP INTO THAT question, it's worth examining what got Walgreens so far in the first place. Collins's account of Walgreens is a parable about steady execution. Drugstores are a commoditized, low-margin business, after all, where success isn't a matter of grand visions so much as figuring out all the small ways of gaining an edge.

The most important edge in the drugstore business is real estate. A new Walgreens store opens every 19 hours, and 450 are slated for this fiscal year alone. (CEO David Bernauer believes the U.S. has room for 12,000 Walgreens.) Those numbers are even more impressive when you consider that these are mostly stand-alone stores built from scratch, not acquired. (CVS's expansion has come mainly from acquisitions, most notably its purchase of all those Eckerds; struggling Rite Aid opened all of seven last year.)

In real estate, of course, location matters. High-traffic areas are obviously better than low-traffic areas; neighborhoods with plenty of senior citizens are prized too -the average 70-year-old takes 16 prescription medicines a year, double the number taken by a 50-year-old. (That last fact explains why the bulk of Walgreens' grand openings of late have been in the Sunbelt: multitudes of retirees.) Judging by the longevity of its stores, Walgreens picks its spots well: Of the 3,600 new stores it has opened over the past ten years, it has closed only two because of poor sales. "We don't make too many mistakes in real estate," says Bernauer, in what for him is a wild display of braggadocio.

Another edge is Walgreens' constant push to drive down costs. According to John Heinbockel of Goldman Sachs, Walgreens has the lowest fulfillment costs in the industry, at $4.95 per prescription; CVS spends $5.89, and Wal-Mart $5.22. Walgreens' cost advantage means a lot when its average store handles 280 scrips a day. And between 1991-when the company began a $60 million program to overhaul its entire supply chain-and 2004, Walgreens reduced its days of owned inventory from 68 to 41, which translates into $2 billion worth of goods it no longer has to stock.

THE PROBLEM FOR WALGREENS AND its ilk is that all the operational excellence in the world is useless if customers have no compelling reason to enter your store. Mail order is now the fastest-growing sales channel for prescription drugs. Last year drugs by mail grew 18%, to $33.9 billion, according to IMS Health, accounting for 14.4% of the total U.S. prescription market-up from 11.8% in 2001. Meanwhile, drug sales at chain stores grew only 6%. Mail order threatens not only the chains' bread-and-butter prescription business (which in Walgreens' case makes up 63% of total sales) but also the higher-margin, "front-end" general merchandise. That's because customers who receive drugs in their mailbox aren't in their local drugstore shopping for cosmetics and candy.

Although drugstores have hedged their bets with mail-order operations of their own (see chart), the lion's share of those sales is generated by pharmacy benefit managers (PBMs) like Medco Health Solutions and Caremark Rx. Highly automated and thus hugely profitable-they don't have stores to build and staff-PBMs can fill and mail a prescription for as low as $2.50, a fraction of what it costs drugstores, according to Bain & Co. partner David Bellaire, an expert on pharmacy operations.

Bellaire says those lower costs mean cheaper drugs for consumers, who also save themselves the shlep to the store to pick up their meds. What's more, PBMs increasingly stipulate that employees get 90-day supplies of so-called maintenance medications-say, Lipitor for high cholesterol-through the mail only. Maintenance medications make up around 60% of the retail prescription-drug market; "acute" medications, such as antibiotics, make up the rest. Benefits consultant Hewitt Associates found that 22% of employers either use such "mandatory mail-order plans" or are adopting them, vs. 16% who said so two years ago. Automakers like General Motors, burdened by enormous health-care costs, have been among the most enthusiastic adopters of mandatory mail.

PBMs really started to take off about ten years ago, and for a time Walgreens grossly underestimated the threat. Indeed, there's no mention of mandatory mail in Walgreens' annual reports until 2004. "We were wrong in not seeing mail order. We admit it," says COO Jeff Rein.

Walgreens certainly sees mandatory mail order now, and it's fighting back. Calling those exclusionary deals between PBMs and employers the "Berlin Walls" of the drug-benefits industry, Walgreens wants to tear them down. One extremely risky gambit is refusing to cut deals with companies that insist their employees use mandatory mail order for maintenance drugs. For example, Walgreens will no longer fill any prescriptions -not even acute medications-for state employees in Ohio. CVS has pulled a similar move on Toyota. It appears that one company may have hit back: GM dropped Walgreens from its pharmacy network on March 1. Industry insiders speculate that GM's move was a preemptive strike against Walgreens' policy. (GM says the move was not motivated by Walgreens' policy; Walgreens says the decision was influenced by GM's PBM, Medco. Medco referred all questions to GM.)

You'd think the safer strategy would be for Walgreens and its peers to entice customers rather than turning them away. And, indeed, they're trying that too. Walgreens, CVS, and others have also started offering 90-day prescriptions in the store through their own PBM arms. Nothing kept drugstores from doing so previously; nothing, that is, except their desire to see customers coming back for refills every month. Walgreens' program, called Advantage90, is now used by more than 150 employers, including Southwest Airlines, and Bernauer claims it's cheaper than mail -at least when measured against Walgreens' own mail-order house. Advantage90 received a huge boost recently when Blue Cross & Blue Shield of Minnesota decided to encourage its members to buy 90-day prescriptions for chronic medications at retail; other states are likely to follow its lead.

For now, at least, Bernauer can point to solid evidence that his stores and mail order can profitably, if not lovingly, co-exist. In fiscal 2004, Walgreens' prescription sales grew 17.8%, just about equaling the mail- order industry's 18% increase. As baby-boomers start to retire in droves, the U.S. prescription-drug market will grow even further, to more than $520 billion by 2014. So Bernauer is betting that there will be more than enough drug pie to go around.

But what about Wal-Mart and the other everyday-low-price bullies? Bernauer admits that when it comes to shampoo, Crest, and other front-end goods, Walgreens won't win when customers shop purely on price.He offers what we'll call the convenience-store argument-i.e., that Walgreens' stores are closer, easier to get in and out of, and less cluttered than the competition's. Indeed, almost half of all Americans live within two miles of a Walgreens (the density of its stores can reach Starbuckian levels-downtown San Francisco has 21 stores within a one-mile radius), and navigating a Wal-Mart Supercenter is no picnic. But both Wal-Mart and Target place their pharmacies close to the store entrance, and grocers often have separate entrances just for pharmacy shoppers.

Still, Walgreens is able to draw shoppers largely because of the accessibility of its stores-most are drive-thrus, and the company has more 24-hour stores than all its competitors combined. Consumer-friendly touches seem to enhance the appeal. For example, Walgreens is the only retailer to have dedicated cosmetics salespeople in every store. Over the past two years the company has also been working hard to tailor individual stores to local tastes. In high-income areas, you'll find a wide selection of pricey skin-care products like Neutrogena anti-aging creams and Biore pore strips. Eric Anglade, a Walgreens manager in uptown Dallas, devotes more shelf space to Walgreens' Rogaine knockoff, which is favored by his gay clientele.

All that helps explain why Walgreens' same-store sales, the key measure of retail performance, rose 10.9% last year and are up 9% so far this fiscal year, besting CVS (up 8.2%, excluding Eckerd), Target (6.2%), Wal-Mart (2.8%), and Rite Aid (down 0.9%).

ONE FINAL POINT TO BEAR IN MIND IS that Walgreens has made it through upheavals before. The starkest example occurred 30 years ago. Back then, the company was known primarily as a dowdy operator of five-and-dimes with lunch counters and of a restaurant chain. (A little-known fact: Walgreens invented the malted milkshake.) In the mid-1970s the company made the wise-and internally controversial-decision to get out of the food business and focus on being a drugstore.

Jim Collins talks about the company as if it were a black belt in corporate rope-a-dope. "Every time you think their model is running out of steam, they surprise you and take it to another level," says Collins. "They don't panic. They almost sucker you in. They want you to underestimate them. Then, bam! They hit you so hard you don't get up." If Walgreens stays sharp on real estate, keeps its costs down, and doesn't allow its fights with the PBMs-and their clients-to get too bloody, it just might survive the drug wars.

FEEDBACK mboyle@fortunemail.com

Picking up prescriptions

Mail-order pharmacy benefit-management companies are thriving, thanks to a low hassle factor (and low prices). To compete, chains are launching similar operations. Here's what the leaders are up to.