#!/usr/bin/env perl use strict; use warnings; use 5.016; my $str = "\x00\x00\x01\x00\x00\x02"; my @vals; # This works - exact multiple of 'x2C' say "length:", length($str); @vals = unpack "(x2C)*", $str; say join "\n", @vals; $str .= "\x00"; # This works - not a multiple of 'SC' say "length:", length($str); @vals = unpack "(SC)*", $str; say join "\n", @vals; # This fails - not a multiple of 'x2C' say "length:", length($str); @vals = unpack "(x2C)*", $str; # ^-- dies here with: 'x' outside of string in unpack say join "\n", @vals;