The way the male brain works, anything remotely sexual can flip that switch. It is very hard when aroused to stop yourself, so the best you can do is avoid as many situations as possible that could make you aroused. These situations are your near occasions of sin. Let’s say you view porn from your computer in your room. You can avoid that situation by moving the computer to another room, cutting off internet access to that computer, or worst case, getting rid of the computer.
Some near occasions will be harder to deal with, such as trying to sleep at night. I regularly have to deal with temptations during sleep. I made a rule if I can’t fall asleep after 15 minutes, I get up and do something productive. I could have gone to bed at 2am and it’s only 5am, but I get up anyways. I avoid the near occasion. Some days I will be all worn out from lack of sleep, but it has to be done to limit the chance I commit a sin. I can offer up the suffering. It also helps me become closer to Jesus. We are united in our suffering for good.