The variable $_ is getting modified inside while
try with
while(my $line = <READ>) {
otherwise, when the file EOF is reached $_ will be set to undef inside func().
try dumping after the foreach loop
print Dumper \@files;
it will output
$VAR1 = [
undef,
undef,
undef
];
UPDATE
Unless you are writing a one liner for some quick task, It is always good to declare and use a local variable for the foreach, for, while, etc. It makes the code understandable and it avoids confusion.
Vivek
-- In accordance with the prarabdha of each, the One whose function it is to ordain makes each to act. What will not happen will never happen, whatever effort one may put forth. And what will happen will not fail to happen, however much one may seek to prevent it. This is certain. The part of wisdom therefore is to stay quiet.