Convert the loops to use lexicals instead of $_.