my @unpack_types = qw( C S L Z* ); $t = unpack('C', $foo); $v = unpack($unpack_types[$t], substr($foo, 1)); #Is $t always a number?