for(@folders){ @list = list of files from folder on ftp server; for (@list){ get file; open, do stuff, close; ftp somewhere else } }