It’s a terrible struggle. I recall one of the Eastern monastic saints, kept vigils sitting in a chair with his hair tied to a beam in his cell, preventing him from sleeping (Eastern monk == long hair, unlike the short haired Western variety, they sound like cats

; anyway, this monk, who is one of our major monastic saints, possibly a desert father, eventually overcame all lustful passion in this manner. But most of us aren’t worthy of being able to fight such a battle, nor in a place where we could even do it.
But I do think monks have the answers on this. In the Catholic Church I would suggest asking a Dominican Friar, assuming they still live in open dormitories as they did according to Thomas Merton in the Seven Storey Mountain. But monastics in general, especially those who are alone much of the time, like hermits or Cathusians, do have to win this battle and most of them do. My understanding is the severe fasting helps to weaken the body and disable the reproductive system to a large extent.
There are occasional cheaters though. Elder Panteilmon of the Holy Transfiguration Monastery left ROCOR and took his monastery and several churches with him after the Russian church received reports of his abusing his monks in this manner and ordered him to undergo a canonical inquiry. His own denomination, which is run by another monk also so accused, recently experienced a dramatic schism when another wave of more incontrovertible accusations came to light. But this is still shocking for Orthodox in North America because although his denomination, HOCNA, was uncanonical, his monastery publishes many of the most widely read prayer books and service books in the English language used by Orhodox following the Greek tradition. I myself nearly bought their Prayerbook before settling on the one from Holy Trinity Jordanville. As an aside the Ruthenian Catholics compiled an Enflish language translation of the liturgy which we use a lot, so these service books do help bridge the Great Schism.
Now there is an Orthodox Saint, John the Faster, who is included in our collection of canon law, the Pedalion, which was compiled by St. Nicodemus of Mount Athos in the 18th century; the canons all predate the great schism however and date from the first Millenium. So unlike your Canon Law or even the Nomoncanon of the Coptic and Assyrian churches which date from around 700 years ago, these canons do not cover a lot of situations and are exceedingly harsh. So the penalties are invariably reduced or waived, and modern bishops have a lot of work to do when a novel situation arises. The penance for masturbation though applied by John the Faster might be enough to stop it: 40 days excommunication and xerophagy with 270 daily prostrations. Xerophagy means no hot meals, no oil, no wine, no meat (except shellfish and caviar, due to a quirk in the letter of the law, but one who is seriously observing it should pass on both) and of course no eggs or dairy products. So basically bread, fruit and vegetables.
Now no Orthodox priest I can think of would impose this penalty; most I’ve met don’t impose penancees at all but simply place their epitrachelion over your head and say the absolution, and offer some words of advise or comfort. But it might be worth self imposing John the Fasters approach if ones doctor agrees with the diet, and ones health permits. On he other hand many theologians including St. Nicodemus, who was one of the earliest proponents of frequent communion in recent times in the Eastern Orthodox Church (where like Rome, most people only took Communion a few times a year) would argue that weekly or even daily partaking of the Eucharist might aid such a struggle. Anyone should get clearance from their priest before trying anything like this.
But with the Great Lent approaching now is a time to work on this passion which affects so many of us in our youth before marriage or defeat of the passion by the mercy of old age, or at a younger age through ascetic struggle, which is perhaps the most virtuous path.