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;