in reply to Default variable $_ is not getting overwritten
But even moving the print "Current line is $_"; after the inner "for" still works, i.e. the whole line is printed, not just its last entry. That's because the "foreach" loop localizes its loop variable (see Foreach Loops).
BTW, one usually uses the diamond operator with while rather than for .
Update: See $_ getting clobbered by inner loop. for an example where the problem really happens.
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
|
|---|