#!/usr/bin/perl use strict; use warnings FATAL => qw(all); sub getBytes { # split string into tokens my @tokens = split '-', (shift); # map array of hex tokens to array of bytes my @bytearray = map ( pack('C', hex2byte($_)), # see below @tokens ); return \@bytearray; } sub hex2byte { my $b = hex(shift); # deal with oversize values $b >>= 1 while ($b > 255); return $b; } # try my $arrayref = getBytes('5e-ff-adad-23'); # check foreach (@{$arrayref}) { print unpack ('C', $_)."\n"; }