if( ! tie %arquivos, IO::Dir, $folder ) { print "Can't read directory ($folder): $!\n"; } else { # ... }