in reply to Only files starting with xxxx
@allfiles = grep { m/^xxxx/ } readdir THEDIR; [download]
And you'll need to modify your $numfiles calculation ...