undef $/; open(IN, "d:\\list.name") || die"Cannot Open file\n"; $str = ; @arr = split(/,|\n/, $str); opendir(DIN, "$ARGV[0]"); @rfiles = readdir(DIN); closedir(DIN); my %seen; # lookup table my @aonly;# answer @seen{@rfiles} = (); foreach $item (@arr) { push(@aonly, $item) unless exists $seen{$item}; } print @aonly; rmdir("$dir\\$_") for (@aonly);