R’ Moshe Cordovero zt”l (the Ramak) was given a special segulah directly from Eliyahu Hanavi, that when one wants to get rid of impure thoughts, he should say the following verse several times until they are gone:
Aish tamid tukad al hamizbayach; lo tichbeh
An eternal fire shall remain burning on the altar; it may not be extinguished. (Leviticus 6:6)
The idea is that each one of us is a miniature Beis Hamikdash, a dwelling place for Hashem’s Shechinah, within which a flame burns eternally and therefore foreign fires such as impure thoughts must be kept out.