# to turn your $str into an array @array = map { vec($str, $_*6, 6) } 0..15; # to turn an array of 6-bit items into a packed string vec($str, $_*6, 6) = $array[$_] for 0..$#array; # or simply to access the $i-th item in the $str, directly: $read_item = vec($str, $i*6, 6) = $write_item; # vec is an lvalue!