For me masturbation to porn seemed like an endless cycle, and I kept at it even when I knew I was hurting myself. Looking back, I fuzzily see that what helped me stop completely was that it became painful.
I discovered masturbation as a child, barely 7 or 8, and orgasmic masturbation when I was 11 or 12. I incorporated imagination and then later Internet porn, maybe when I was 15.
For me, awareness was the key to kicking the habit. You can be aware of when you are starting to watch porn. You can see yourself clicking at the link. You can see your thoughts starting to jump, drawing on memory and on images from the past. Only then does the body reaction begin (after the thoughts).
Become aware. That is my advice to someone who knows masturbation is hurting him, but can’t stop.
Gradually, I became aware of my thoughts before I got the urge. I got to know how I think, and thus to know who I was.
Eventually I had a choice about whether to proceed. This didn’t involve punishing myself, or running away from those thoughts. It just involved watching them—without judgment.