#!/usr/bin/perl -w use Cwd; my $dir = getcwd; my $dirs = "/opt/DSPKG"; opendir(BIN, $dirs) || die "Can't open $dirs: $!"; my @array = grep { -d "$dirs/$_" } readdir BIN; foreach my $file (@array) { open(MYFILE, ">/tmp/pkgtest") || die "cant open pkgtest: $!"; print "$file\n"; }