my %SEEN; my $key; open( FH, '<', "image.raw" ) or die $!; binmode(FH); my $startpos = 10; # skip header seek(FH, $startpos, 0); $/ = \42; # set record size while( ) { $key = join("", unpack 'H42', $_ ); $SEEN{$key}++; # not sure how to calculate stop } for my $key (keys %SEEN){ print "key $key seen $SEEN{$key} times\n"; } # Add method to go from hex key to numeric rgb values if you want