my $startpoint = 0; my $endpoint = 99; if ( $type eq 'row ){ $startpoint =1, $endpoint = 100 } foreach my $field ( $startpoint..$endpoint ..... .....