in reply to checking for reserved characters

my @chars = split //,$folder; foreach (@chars){ if($_ eq "*" || $_ eq '$' || $_ eq "&" || $_ eq "." || $_ eq "?" || + $_ eq '\'){
Ignoring for now whether that's the right set of reserved characters, your code can be written far more succinctly and efficiently as
if ($folder =~ /[$&.?\\]/) {

Dave.