After studying your updates, private messages, and documentation for 'pack', I was able to fix my previous code by packing one extra (arbitrary) character, and not unpacking it. However, I noticed that the 'pack' was overkill. I could concatenate three extra nulls to the end of the original ASCII string and unpack as much as necessary. The length ($l) has to be twice what it was before because now I am unpacking two hex characters for every one ASCII character that I had been packing.
use strict;
use warnings;
use Test::More tests=>4;
my @examples = (
[qw( example. 6578616d706c652e )],
[qw( example.1 6578616d706c652e31000000)],
[qw( example.12 6578616d706c652e31320000)],
[qw( example.123 6578616d706c652e31323300)],
);
foreach my $example(@examples) {
my ($Origin_Host_CER, $required) = @$example;
my $l = 8*int((length($Origin_Host_CER)+3)/4);
my $result = unpack("H$l", $Origin_Host_CER . "\x00" x 3);
is($result, $required, $Origin_Host_CER);
}
RESULTS
1..4
ok 1 - example.
ok 2 - example.1
ok 3 - example.12
ok 4 - example.123