Ewwwwww. Perl is a very handy language for interfacing with server software, but I gotta agree that its a real *&$£# to get everything working nicely. My advice is to pop to
http://www.hotscripts.com or something and see if a script already exists to do the things you want. Chances are that if its possible, hotscripts.com will have a script available for it...