the best way to control it is first, prayer, always pray when you are tempted, and say your daily prayers, especially the rosary,
and what you really need in order to gain control over yourself is mortification, which you can read about here -
gaiaonline.com/guilds/viewtopic.php?t=13047443
mortification is the practice of self denial, if you deny yourself in small ways, then it will help you to gain strength in bigger things, such as resisting impure desires, or any sin at all,
so if you want to give it a try, talk to your priest about it, or read what the saints have to say on the matter,
we all as Catholics should be practicing mortification actually,
“For if you live according to the flesh, you shall die: but if by the Spirit you mortify the deeds of the flesh, you shall live.” Romans 8:13
“Always bearing about in our body the mortification of Jesus, that the life also of Jesus may be made manifest in our bodies.” 2 Corinthians 4:10
there is alot to be gained by mortification, fasting, and penances, by those things we gain control of our will, after all, what’s so great about having a free will if you can’t control it? we tend to let ourselves become slaves to the flesh, or the world, or the devil, but in order to become slave to God, we must be able to give Him our will, and in order to do that, we must have control of it.
well, other than that, the best things you can do to overcome this sin are, prayer, confession, Holy Communion, spiritual reading(especially the lives and writings of the saints), Eucharistic adoration,
and when faced with this temptation, do not attempt to fight it, but instead flee from it!
first of all, when you first realize the temptation, do not think about it, but just get up and walk away, either go somewhere where there are other people, or go out for a walk, or whatever you have to do to get out of there,
or if your temptation is triggered by impure thoughts(which are also mortally sinful when consented to) you should pray immediately when you realize the temptation “Precious Blood of Jesus Christ, wash over me, protect me from the wickedness and snares of the devil” and then pray “Jesus, Mary, Joseph, Saint Maria Goretti, Guardian angel, help me” and then try to think of something else, something you enjoy very much that is not immoral to think about.
during times of temptation, your two best friends are prayer, and your own two feet to get your out of there.
or if you are having these temptations in bed at night, then try sleeping with a crucifix in your hand, and always make sure to say your night prayers,
one prayer in particular that i think will help(because it helped me immensely) is saying 3 Hail Marys in the morning and at night for the intentions of purity and holiness, which was the practice of Saint Maria Goretti, i would highly recommend taking up that practice and continuing it for the rest of your life.
and confession is also going to be a big help for you if you use it devoutly, meaning once a week or at the least once a month, and even if you don’t have mortal sins to confess, confess your venial sins and your temptation to mortal sin, because by confession even the temptations in confession you will gain special graces to gain strength over those temptations.
and during your Holy Communion with Jesus, ask Him to free you from this sin, and always ask Him for help in all of your spiritual and temporal needs,
Jesus cured many people when He walked the earth, and it was by their faith that they were cured, so just have faith In God and He most certainly will help you,
communion is a very special and beneficial time that you have with Jesus, never waste a moment of that time.
and just be patient with yourself, don’t despair if you fall, instead ask God to help pick you up again, get yourself to confession, and earnestly strive not to sin that way again, because that is all God asks, that you simply try…
well, i will be praying for you, and i hope this helps,
take care.