my $directory = '/path/to/directory'; my @subdirs; opendir(DIR,$directory) or die $!; while(my $file = readdir(DIR)){ my $path = $directory.'/'.$file; push(@subdirs,$path) if(-d $path && $file != /\.alt$/); } closedir DIR;