my $page = $q->param('page') || 1; my $rows = $q->param('rows') || 10; my $order_by = $q->param('order') || 'date DESC'; # And you should check, untaint the data, before using, # even an option like page= ... # Your code for getting the comments could be written as my $rs = $schema-> .... # and then while (my $comment = $rs->next) { ... } # this way, less memory is getting used by perl # Why not say my $pager = $rs->pager; # instead of this $rs->pager->...