NEW YORK (AP) _ Pan Am and TWA, two of the oldest - and weakest - airlines, neared agreement on a business marriage that would end their longtime rivalry and change the cast of characters in a deeply troubled industry.

But Pan Am may have to seek bankruptcy protection anyway.

Carl C. Icahn, chairman of Trans World Airways, had proposed a buyout of Pan Am Corp. last weekend in a deal worth about $375 million. Pan Am Chairman Thomas G. Plaskett responded with a letter Friday saying the deal could be ''advantageous to our shareholders, employees and other constituencies.''

But in a frank admission of Pan Am's critical money shortage, Plaskett said Pan Am would need an infusion of cash before the purchase could be completed.

''Under the circumstances, it would be futile to enter into a transaction without any provision for bridge financing, especially if TWA were not to commit to close the transaction regardless of our financial situation,'' Plaskett said.

Icahn sent a letter to TWA's employees saying he had been considering ''the possibility of providing Pan Am with debtor-in-possession financing. This is a type of financing which might be possible if Pan Am decides to file a petition for reorganization in bankruptcy.''

In an interview published in today's New York Times, Icahn said of a bridge loan: ''Even though it's going to be tough, I'm going to make every effort I can.''

Combining TWA and Pan Am would mark the end of independence for Pan Am, which pioneered overseas air travel but has lost staggering amounts of money over the past decade. It has survived by selling itself in pieces.

Earlier this year it agreed to sell London routes and some other assets to United Airlines for $400 million.

Icahn had written to Plaskett a letter dated Sunday that offered to buy Pan Am's 150 million outstanding shares for $1.50 a share in cash and $1 a share in either preferred stock or notes.

''In these extremely complicated and troubled times for the airline industry, a combination of TWA and Pan Am might offer both of us the opportunity to compete with the three major U.S. airlines,'' Icahn wrote.

The industry's three dominant players are American, United Airlines and Delta Air Lines.

Friday was the deadline for Pan Am to accept.

In his responding letter, Plaskett asked Icahn to ''send us promptly a detailed term sheet indicating among other things the basis on which you would be willing to provide bridge financing, precisely what you envision as conditions of closing, and the specific terms of the securities you are proposing to offer.''

Pan Am's letter, which didn't say how much cash was needed, was released shortly after Standard & Poor's issued a statement raising the possibility that Pan Am would have to seek bankruptcy court refuge if it couldn't raise cash.

The airline industry is approaching record losses because of fuel inflation incited by the Persian Gulf crisis and slackening demand for air travel. Weak airlines such as Pan Am and TWA are under the biggest strain.

Icahn's offer for Pan Am came at the same time he announced plans to sell all of TWA's London routes and some other assets to a healthier rival, American Airlines, in a package worth $625 million.