while (defined($long_file_name = readdir(DIR))) { my $short_path = Win32::GetShortPathName("$dir\\$long_file_name"); (my $short_file_name = $short_path) =~ s#^.*[\\/]##; ... }