Where does the lib::Db come from? it doesn't seem to be used anywhere.
Anyway, you speak of "issues", but don't mention what the problem is. Is the database engine throwing an error? If yes, which? Or are you getting a different result than expected? If yes, what do you get, what do you expect?
If you are unsure what values some variables contain, use Data::Dumper to find out.
One problem I can see with your code is that if @data doesn't contain a number of items that is divisible by 50, then the last query will have lots of trailing undefs. Not sure if you want that.