my @in = (30, 14, 27, 2, 17); my $width = 6; my $offset = 0; my $out = 0; $out |= ($_ << ($offset++ * $width)) for @in;