if (-e "$protected_folder/$protected{'file'}"){ Pass file for downloading. } else { print "HTTP/1.1 404 Not Found\n"; print "Content-type: text/html\n\n";}