I think i see your problem...
You have a main directory receiving emails, every 5 minutes it dumps one email into 1 of three directories(sequentially counting, and restarting when after an email has been put in the last directory).
Now, do you only expect 1 email per 5 minutes, or many? if many, then do you want it to dump all of the emails to the rotating directory? or perhaps just to split the emails evenly between the x directories?
how about...
@dirs = ("/dir_1","/dir_2","/dir_3");
while() {
sleep{300);
mv /dir/main/ $dir[$i++%3];
}