in reply to rename and create directories

Try File::Copy. The move function will do what you want.

Update: Hmmm, actually, if it doesn't do the "create directories" bit -- the destination doesn't exist at all -- then you may need to also muck about with File::Path::mkpath.