in reply to Generating IPv6 Masks

A pack/unpack solution:
sub make_netmask { my $mask = shift; return if $mask < 0 or $mask > 128; return unpack('C*', pack('B*', '1' x $mask )); }
Right-padding with zeroes can be accomplished by changing B* to B128.

The PerlMonk tr/// Advocate