in reply to variable declaration

As written your code is not Perl or any other language that I recognise. However, piecing together hints from your rather incoherent description and your totally random code it may be that the following is somewhere near what you want:

use strict; use warnings; my $obj = bless {i => 1, j => 0}; $obj->run (1100, 20); sub run { my ($self, $end, $start) = @_; my $records_to_be_feched = $end - 20 * $self->{i}++ - ($start - 20 * $self->{j}++); }

There are many ways this could be achieved. I have chosen to use a light weight object to carry the counters around rather than make them global variables. I've no idea what start and end should be so I've just passed them in as parameters.

True laziness is hard work