in reply to Opendir, readdir & closedir.

perldoc -f readdir says: Returns the next directory entry for a directory opened by "opendir". If used in list context, returns all the rest of the entries in the directory. If there are no more entries, returns an undefined value in scalar context or a null list in list context.

That means it's behaving exactly as documented: the grep called it in list context, it returned a list of all files, and now it will be returning a NULL list until you do an opendir again.

It's the same thing as trying to read from a file where you've already read all the contents.