You need to split the string into individual characters, loop over every character, and call ord
in the loop.
my @codes = map ord, split //, $str;
say join '.', map { sprintf("%02X", $_) } @codes;
Conveniently, unpack 'C*'
does all of that.
my @codes = unpack 'C*', $str;
say join '.', map { sprintf("%02X", $_) } @codes;
If you do intend to print it out in hex, you can use the v
modifier in a printf
.
say sprintf("%v02X", $str);