replace for loop $_ to lexical variable

I encountered $_ conflict problems, so replace $_ to lexical.