I have ... arrays a_1,a_2,a_3...a_N
That's oh-so-wrong. Always use use strict;, which specifically forbids this (among other things). You should use an array of arrays instead.
i need "variable" number of foreach loops based on variable "$count" Is this possible in PERL?
If you mean "Perl" and you fixed the error mentioned above,
use Algorithm::Loops qw( NestedLoops );
splice(@aoa, $count);
NestedLoops(\@aoa, sub { print(@_); });
Or if $count == @aoa,
use Algorithm::Loops qw( NestedLoops );
NestedLoops(\@aoa, sub { print(@_); });
Algorithm::Loops