Generate gate with a parametrized number of inputs
Try

assign out = ^(in &amp; parameter);


The &amp; selects those bits which are 1 in parameter, and then ^ will XOR them all together. Those bits which are 0 in parameter will be ignored.