The United Nations launched a worldwide appeal on Friday for hundreds of millions of dollars of aid it said would be needed to help some five million refugees back into war-torn Afghanistan.

U.N. High Commissioner for Refugees Jean-Pierre Hocke, talking to reporters the day after the signing here of an Afghan agreement intended to facilitate the refugees' return, said the problem would be massive.The agreement, in addition to providing for a Soviet troop withdrawal, commits Afghanistan to allow all refugees in Pakistan to return home if they wish.

About 5.4 million Afghans, about one-third of the population, have fled to Pakistan and Iran from the 9-year-old civil war. Official estimates put the number in Pakistan alone at 3.1 million.

Hocke said he was consulting other agencies and governments and hoped to present potential donor governments with a detailed plan of action in the next 10 days.

If there were a mass return of refugees, hundreds of millions of dollars would be needed in the next 12 months.

Hocke appealed to the signatories of the settlement Afghanistan, Pakistan, the Soviet Union and the United States to facilitate the execution of these accords "and above all to guarantee the conditions according to which the refugees will choose to return home freely."