#!/usr/bin/perl -w use strict; # Some example "keywords" and how they should be displayed my %kwfmt = ( "RT" => "A", "PN" => "A", "SN" => "A", "AB" => "H", "CD" => "H", "B1" => "H", ); # The kind of thing I will see in my file my @record; $record[0] = pack ("A2CA7", "RT", 7, "testing"); $record[1] = pack ("A2CH16", "CD", 8, "01020304FFDDEC19"); # Prints ASCII fields fine, truncates hex for (my $i=0; $i<2; $i++) { my ($kw) = unpack("A2", $record[$i]); my ($rdata) = unpack("x2C/$kwfmt{$kw}", $record[$i]); print "$kw $rdata\n"; }