opendir(DIR, $dirname) || die "can't opendir $dirname: $!"; my @directory = readdir(DIR); my @filenames = grep { -f "$dirname/$_" } @directory; # Either use the array @directory, or rewinddir(DIR) here, and grep readdir(DIR) twice. my @directories = grep {-d "$some_dir/$_" && !/^\.$/ && !/^\..$/} @directory; closedir DIR;