in reply to Open, While and memory management

They are not exactly equivalent, in that the latter will read into $_, destroying any previous content. You would need to prepend the "local $_;" mantra to make them indistinguishable from calling code's point of view (though their precise behavior will still differ of course).

Anyway, on your question, I seem to recall word being that my-variables used directly in the loop construct (ie while(my $var) and for my $var) are scoped into the loop's block's context, but allocated in the surrounding block's frame. In conjunction with them apparently not being deallocated at the loop's end but rather at the surrounding block's end in older 5.5.x versions of Perl, that would explain why your code "leaks".