Sefer Hamiddos (by Rabbi Nachman of Breslov) “Hirhur” 2:13:
If you are about to go out into the street, yet fear you might see pretty women and have untoward thoughts, say the following verse: “הֵן אֶרְאֶלָּם צָעֲקוּ חֻצָה מַלְאֲכֵי שָׁלוֹם מַר יִבְכָּיוּן”.
Tried and true.
(Yes, I already posted this in Hebrew, but it’s too important not to translate and duplicate.)