chdir "/home/www"; opendir DIR, "."; my @third_level_dirs = ( # 3. This tests for their presence grep { -d } ( # 2. This adds /logs to the end map { "$_/logs" } ( # 1. this returns all directories but . & .. grep { !/^\.\.?$/ && -d } (readdir DIR) ) ) ); closedir DIR;