# The raw data as you might read it fro the file $raw = '2010/02/03 10:52:03.123456'; print length $raw;; 26 ## First unpack in your main loop $level1hex = unpack 'H*', $raw; print $level1hex;; 323031302f30322f30332031303a35323a30332e313233343536 ## Now re-unpack it two different ways in you print_trailer() sub $level2text = unpack 'A*', $level1hex; print $level2text;; 323031302f30322f30332031303a35323a30332e313233343536 $level2hex = unpack 'H*', $level1hex; print $level2hex;; 33323330333133303266333033323266333033333230333133303361333533323361333033333265333133323333333433353336 #### my @trlname = ( "Record Type", "Date", "Record Size", "Number Record", "Application", "Version", "Data Rec. Type", "Extra", "newLine" ); my @trlsize = (6, 28, 8, 14, 32, 10, 6, 32, 2); #### my @fields = unpack 'A6 A28 A8 A14 A32 A10 A6 A32 A2', $data; print $trlname[ $_ ], ' : ', $fileds[ $_ ] for 0 .. $#fields; #### sub print_trailer { my $data = shift; my @fields = unpack 'A6 A28 A8 A14 A32 A10 A6 A32 A2', $data; print $trlname[ $_ ], ' : ', $fields[ $_ ] for 0 .. $#fields; } ... while (read (DATA, $data, DATALEN) != 0) { if ($data =~ /^T/) { print_trailer($data) if ($raw); } else { display_data($hex); } }