There is no verse in the Holy Quran that appears to have a cure for this habit. However, getting married and fulfilling your desires in the permissible way is one of the best ways to stop committing this prohibited act. It was reported that whoever gets married, two thirds of his religion is guarded.
One must make sure that she follows one of the three religions before he can marry her. If he knows that she follows one of these religions but does not know which one, then he does not need to find out.