A few things in random order:
- If you can map the UNC resource and copy to it as a drive letter, you should also be able to copy to the UNC path directly. There is no special magic in the drive letter mapping and xcopy can handle that without problems.
- As you say you are not very familiar with UNC: Have you checked the correctness of your path? Your sample code reads $source="\\\\server\\dir\\files\\";. So "dir" is a "share" provided by server?
- Using robocopy.exe instead of xcopy is more flexible. At least I always prefered that for the last ten years for such synchronisation task under Windows. Additional pro is better error messages in case of failure. Cons would be that you have to grab a copy of robocopy from a "Windows Resource Kit" and copy it to the machine for using.
- When you go the road with using Perl built in copy mechanism/modules, be aware that all path separators can be written as forward slashes, (i.e. $source = "//server/share/dir";) because the underlying API did allow that since earliest DOS times; only the DOS command prompt forces you to use backslashes.