in reply to working with directories

You failed to tell us what your problem is. Are we supposed to guess?

You don't need a while loop if you are reading the directory in list context:

my @folder = readdir DIR;

You may also take a look at the glob function, which is often more practical than opendir/readdir.