How do i remove the duplicate names and how do i specify the directory i.e /home/Backup/windows. I will be changing regularly in the script. Once i remove the duplicate names i will work on how to get the last backup

The easiest way to remove duplicates is genberally to use a hash to store the items that you have already seen. When you see a server name, check if it is in the hash. If it already there, juste ignore it. If it is not there, then add it. At the end, your hash will contain server names without duplicate.

foreach (sort keys %files) { # the previous line iterates over the unique file names in the hash %files. Each name is stored # in the $_ special variable my @files_latest = glob("$_*"); # the previous line looks in the directory for files having each of the unique file names #and stores the result in the @files_latest array print "$files_latest[$#files_latest]\n"; # this prints the last element of the @files_latest array, i.e. the most recent backup