This is the answer to a question on a mailing list.
When you look at a person, learn to look upon the person not as a physical object but as a person with thoughts, emotions, hopes, disappointments, likes, dislikes, etc. We do this naturally with people whom we know well. With strangers with whom we have not personally interacted, what usually comes before us is the appearance of the person. Learn to look beyond the appearance into the deeper aspect of the person. By auto-suggestion, learn to see people as minds and not as bodies. One strong way is to mentally say “God bless you” with all sincerity to the person whose physical form is distracting you. This will immediately make you look upon the person as a thinking and feeling entity and the physical form will not distract you anymore. Always look people in their eyes. You will see the jiva within. The physical form will fade into insignificance once you see the jiva within.
This attitude can be stabilized by doing a lot of social service. When you keep serving strangers over a period of time, you will naturally start looking upon strangers also as people with feelings. Then the physical form will not distract you.
When you have lust in the mind, you cannot have a smile on the face. The converse is also true. When you have a smile on the face, you cannot have lust in the mind. So one easy way to maintain purity is to be cheerful and smile.
Parallelly, you should also learn to look upon yourself not as the body but as the mind. This can be attained by mental activity like japa, reading good books, solving puzzles, etc. Doing yoga asanas also create this attitude because you work with your body as if it is an object. But exercise like weights, cycling, etc do not help here because then you are using your body on some external objects. The beauty of yoga asanas is that the body itself is the object. So it reduces the identification with the body.
You should also learn to look upon God as a thinking and feeling person. When you do worship, don’t look upon God as an object of worship. Look upon God as a thinking, feeling, living person who is accepting your offering with joy and compassion.
Your idea of these three – yourself, the people in the world and God – Jiva, Jagat, Ishwara – always go together. Changing your attitude in one of them has the effect on the other two. This is how all the yogas give the same result.
This is the first step.
Later, when you have learned to look upon yourself as the Atman instead of as the mind, you can learn to look upon other people also as Atman instead of as the mind. Then God will also be the impersonal Brahman.
But the first step itself is a great achievement and will take you quite far.
See also the blog entry: How to overcome lust