in reply to unpacking 6-bit values

Probably roboticus solution is better, but anyway:
  1. unpack your data as an hexadecimal string
  2. use a hash to convert every three hexadecimal digits (12 bits) into two bytes (16bits).
use Data::Dumper; my %t; for my $i (0..63) { for my $j (0..63) { $t{sprintf "%03x", $i*64 + $j} = [$i, $j]; } } my $buf; my @bytes; while (read STDIN, $buf, 4096) { my $hex = unpack "H*" => $buf; while ($hex =~ /(...)/g) { push @bytes, @{$t{$1}}; } } print Dumper \@bytes;