$file=~m/^.*(\\|\/)(.*)/; # strip the remote path and keep the filename $name = $2; open(LOCAL, ">$dir/$name") or die $!; #open file