John Piper's acronym ANTHEM is the best tool I know of for guarding one's mind.
In an article he published in 2001, Piper gives his six-step plan for annihilating lustful thoughts. First, Avoid lustful temptations. Second, "Say No to every lustful thought within five seconds. And say it with the authority of Jesus Christ." Next, Turn your thoughts to Christ. Fourth, Hold thoughts of Christ in your head. Fifth, "Enjoy a superior satisfaction. Cultivate the capacities for pleasure in Christ." Sixth, "M into a useful activity."
I can testify from experience that ANTHEM is a helpful guide. Just last night, I fought back with its recommended defenses against temptation. It works. Read the whole thing and use it.