This thread should help get you on your way:
I forgot to say that a subroutine to extract batches of lines from a list of items exists and may also help you out. You can find it here:
For more information, see the wiki Searching the Forum for Answers section.