Avoid areas where there is a greater chance of you seeing women dressed inappropriately such as the beach or shopping malls. Turn your sight away from anything inappropriate such as billboard advertisements or online dating ads. The longer you stare at something attractive the more you will want to look and go further. It does not get out of your system by indulging in it, as some people claim. Actually, it is like a drug that gets into your system and you want to have more.
Keep yourself busy with work, reading books, or other productive things. If you see things online then use your computer only when you are in a public area. Be careful of the videos and movies you watch and try to find alternatives where women are dressed more appropriately. Avoid bad friends who encourage you to look. Stay in the company of pious people where you would be embarrassed to do that in front of them.
Try fasting to control your desires. Avoid eating aphrodisiac food which stimulates your desires. Keep asking Allah to protect you from looking at unlawful things. Get married if you are ready, or get yourself ready. If you are married, try to spice up your love life.
If you continue to fall into this sin, consider a reward and punishment system to help you in your struggle.
Shaykh Mustafa Umar