For five years, Maryam, the hairdresser, and Karim, the home appliance salesman, carried on a love affair, meeting secretly at the house where Karim lived with his parents. The young couple's relationship was officially sanctioned by Iran's Islamic Republic, even though unmarried couples who have sex or even date and hold hands can be arrested, fined, even flogged. That is because Maryam and Karim were married.

Sort of.

They had a valid contract of temporary marriage.

Iran is a country where rules are fluid, where people of all classes and degrees of religiosity pride themselves on finding loopholes in the Islamic system. Temporary marriage, or sigheh, is one of the oddest and biggest.

The practice of temporary marriage is said to have existed during the lifetime of Muhammad, who is believed to have recommended it to his companions and soldiers. The majority Sunni sect in Islam banned it; the minority Shiite sect did not. Historically, the practice was used most frequently in Iran by pilgrims in Shiite shrine cities like Meshed and Qum. Pilgrims who traveled had sexual needs, the argument went. Temporary marriage was a legal way to satisfy them.

Maryam and Karim chose temporary marriage for a practical reason. ''We went out a lot together, and I didn't want to get into trouble,'' Maryam, 31, said. ''We wanted to have documents so that if we were stopped on the street we could prove we weren't doing anything illegal.''