U.S. stocks fell on Friday as data showed U.S. inflation hit the highest level in 2-1/2 years last month, making investors cautious.

The Nasdaq was dragged lower by concerns about competition threatening Nvidia and claims by Yahoo that one of its units was restructured without its knowledge.

The year-over-year rise in the government's Consumer Price Index to 3.2 percent was the highest since October 2008 and met economists' forecast. A separate report showed consumer sentiment improved in early May as optimism about jobs reduced the pinch from high gasoline and food prices.

CPI was right in line, net benign, but people are concerned we're still going to have to deal with inflation, said Ken Polcari, managing director at ICAP Equities in New York.

People are going to take advantage and reallocate some assets, build a more defensive-type portfolio, he said, adding the S&P could be stuck in a 1,330-1,355 range in the following weeks.

In the last weeks, leadership in the S&P 500 has shifted from cyclical sectors like energy and basic materials to sectors with more stable growth like health care and utilities.

The Dow Jones industrial average <.DJI> lost 51.05 points, or 0.40 percent, to 12,644.87. The Standard & Poor's 500 Index <.SPX> dropped 5.84 points, or 0.43 percent, to 1,342.81. The Nasdaq Composite Index <.IXIC> fell 15.86 points, or 0.55 percent, to 2,847.18.

Commodity prices rose sharply until recently. Steep declines in the past weeks in crude oil and silver have hurt risk appetite and prompted traders to brace for further unwinding of dollar-funded bets on risk assets.

Yahoo Inc shares fell 5.6 percent to $16.21 after it said the Alibaba Group restructured the ownership of Alipay, one of China's largest online payment businesses, without the knowledge of Yahoo and Softbank, two of its stakeholders.

Nvidia Corp shares fell 6.7 percent to $19.12 on concerns about growing competition in its core PC graphics market even as the company on Thursday gave a rosy outlook for its mobile chip business.

Electronics testing equipment maker Agilent Technologies Inc reported better-than-expected quarterly results and raised its full-year outlook. Its shares jumped 5.3 percent to $52.96.

(Reporting by Rodrigo Campos; Editing by Kenneth Barry)