in reply to Only files starting with xxxx

use the grep function :

@allfiles = grep { m/^xxxx/ } readdir THEDIR;

And you'll need to modify your $numfiles calculation ...