use strict; use warnings; use Email::Folder; use Email::LocalDelivery; my $count = 0; my $box_size = 100; my $boxbase = '/home/jonathan/tmp/testmail/spam'; my $box = Email::Folder->new('/home/jonathan/mail/spam'); while ( my $mail = $box->next_message ) { my $newbox = $boxbase . int($count++ / $box_size); Email::LocalDelivery->deliver($mail->as_string(),($newbox)); }