The Dow and S&P 500 finished at new 5-year highs Tuesday, as investors grew hopeful about a potential merger between OfficeMax and Office Depot.

Investors have been pulling back a bit after a strong start to the year. All three indexes are up between 6% and 8%, with the Dow just 1.2% shy of its all-time high, hit in October 2007. The S&P 500 is less than 3% below its record high, also set in October 2007.

Driving the gains Tuesday were shares of OfficeMax(OMX) and Office Depot(ODP), which both rallied after media reports said the companies were in advanced merger talks, citing unnamed sources. Staples(SPLS), the other major office supplies retailer, gained about 13%.

Staples not an 'easy' button investment

The talks come as mergers and acquisitions have picked up. Just last week, US Airways(LCC) announced a merger with American Airlines parent AMR(AAMRQ); Warren Buffett's Berkshire Hathaway(BRKA) announced it was buying ketchup maker Heinz(HNZ); and Comcast(CMCSA) announced a $16.7 billion deal for the 49% of NBC Universal that was still owned by General Electric(GE).

After the closing bell, Dell(DELL) reported earnings and revenue that fell from a year ago but topped analyst expectations. Controversial nutritional supplements company Herbalife(HLF) also announced better-than-expected earnings and sales figures. The company also boosted its outlook for 2013 and issued a 30 cents per share quarterly dividend.

A hearing began Tuesday in David Einhorn's lawsuit against Apple(AAPL). Einhorn's hedge fund, Greenlight Capital, has accused Apple of hoarding billions in cash and wants a judge to block a "bundled" shareholder vote, scheduled for Feb. 27. Einhorn wants shareholders to vote separately on an Apple proposal that would limit the company's ability to issue high-yielding preferred stock.

Tuesday's homebuilders confidence report did little to soothe investor's nerves about the wobbly economic recovery. The National Association of Home Builders' Housing Market index fell for the first time in nearly a year in February. Economists were expecting the index to edge up to a six-year high.

Separate reports on housing starts and building permits will follow on Wednesday, and data on existing home sales will be released Thursday.