while(readdir $dh) { next unless -f and /\.log$/; # Process log file here }