Well first off a key part of this is the DataBase you select to use. MySQL has LIMIT which will make you life very easy, other DB's may do it a little differently (or not at all). So I will assume you are using MySQL.
Now based on your request I am unable to tell your level of scripting proficiency but I get the feeling you are probably new to Perl so here are some good places to start.
I hope that helps point you in the right direction... you may have a lot of reading to do.
If you get stuck come on back and ask.