use Algorithm::Loops qw( NestedLoops ); my @spec = ( [ 'static1' ], [ 'ar1', 'ar2' ], [ 'static2' ], [ 'ar3', 'ar4', 'ar5' ], ); NestedLoops(\@spec, sub { print(join(', ', @_), "\n"); });