Here is the script I use for maintaining a local mirror. It isn't perl, and I believe it may require bash (untested on anything else at least). It also wasn't written with the idea of being run automatically, but it could probably be thrown in a cron job.
I don't mirror everything in my situation, just the packages my application needs. I create some packages locally, so it has some methodology of not trying to delete or download those local packages from the web. I only use tcz packages and the core.iso, so this is all this script handles currently.
Requires some manual adjustment of variables at the top of the script before using to set up directories, local packages, the web mirror to use etc.
tc-mirror-utils.sh
* with no parameters it just updates info.lst and tags.db (this happens with the other two modes of running too)
* with '-U' or '--update' it downloads the md5.txt of all packages in the local mirror from the web mirror, compares them, and if it gets a failure will redownload that package. (prompts before deleting the old package) This must be the first command line argument if you want this to work.
* also accepts a list of package names as a command line argument, it will try to download each package listed in this way from the web mirror.
You can pass new packages to download after the '-U' command to update. It will just fail and md5 check for the non-existant .md5.txt file, and then prompt to download the new package.
It also tries to do dependency resolution as well.