in reply to Precedence (spot the bug)

or perhaps you could look at or :) :
my @files=readdir(DIR) or die “$!”;
.....works just fine too.