sub bcd { local $_ = shift; # enforce two digits $_ = "0$_" while 2 > length; die "too big" unless m{^(\d)(\d)$}; return chr(16*$1 + $2); }