How many 'ff' character pair sequences are in the string qq{\x0f\xf0\xff} after you've unpack-ed the string?
c:\@Work\Perl\monks\perl -wMstrict -le
"my $file = qq{\x0f\xf0\xff};
my $data = unpack( 'H*', $file );
my $count =()= $data =~ /ff/g;
print $count;
"
2
If you want to count the number of 0xff characters in the raw file, maybe better to concentrate on 0xff:
c:\@Work\Perl\monks>perl -wMstrict -le
"my $file = qq{\x0f\xf0\xff};
my $count =()= $file =~ /\xff/g;
print $count;
"
1
Or perhaps better with
tr/// (update: see Quote-Like Operators in perlop):
c:\@Work\Perl\monks>perl -wMstrict -le
"my $file = qq{\x0f\xf0\xff};
my $count = $file =~ tr/\xff//;
print $count;
"
1
Update: I haven't checked this, but if you're running under Windoze, there may be a problem arising from the fact that Windose uses a \x0d\x0a character pair to represent a newline in a file, but this may be translated into a \n (newline) single character when the file is read depending on the read mode being used, e.g., binmode. stat will report the number of characters the operating system sees, i.e., the number before any file-read translation, and this may throw your calculation off a bit versus what the HxD hex editor (whatever that is and however it works) reports.