open output,">:utf8","D:\\directory1\\output.doc" or die "Couldn't open STDOUT: $!"; opendir DIR,"D:/directory1" or print " \ncould not open the directory : $!"; print OUTPUT "\nreading the list from the directory\n"; while ($list=readdir DIR) { if(-d $list) { print OUTPUT "$list\n"; } }