http://revach.net/article.php?id=4912

Section: Daas Torah   Category: Agados HaShas
Hafla'ah - When The Most Potent Medicine Does Not Work

The gemara says in Brachos (5a) that a person must force his Yetzer Tov to relentlessly fight his Yetzer Hara. If he wins the battle then he is fortunate, if not then he should learn Torah. If that doesn't work he should say Krias Shema. As a last resort he should remember the day of death. All the Meforshim ask, Torah is the greatest weapon against the Yetzer Hara, if that fails how can Krias Shema or visions of death provide better protection?

The Anaf Yosef brings from the Haflaah as follows. True that Torah learning is the most potent way to fight the Yetzer Hara, but only Torah Lishma. If you learn Torah to satisfy your own thirst for knowledge or personal gain, it will not slow down the Yetzer Hara. In that case you should say Krias Shema which is Kabalas Ol Malchus Shamayim. Shema is about Mesiras Nefesh and being Mivatel yourself and your desires to the will of Hashem. This will empower your Torah to conquer the Yetzer Hara.

Even if he says Shema and is totally devoted to Hashem, the Yetzer Hara may convince him that he is perfect in Torah and Avodas Hashem. This haughtiness will cast him away from Hashem, who despises Baalei Gaava. In this case he must think of his ultimate demise, which is enough to humble even the high and mighty.