#!/usr/bin/perl -wl use strict; my $count = 0; my $long; open FILE, "file.txt" or die "Couldn't open file: $!\n"; binmode FILE; while (read FILE, $long, 4) { $count += unpack'%32b*', $long; } print $count; __END__ #### #!/usr/bin/perl -wl use strict; my $count = 0; my %lookup; my $byte; open FILE, "file.txt" or die "Couldn't open file: $!\n"; binmode FILE; while (read FILE, $byte, 1) { next unless ord $byte; if ($lookup{$byte}) { $count += $lookup{$byte}; } else { $count += $lookup{$byte} = unpack'%8b*', $byte; } } print $count; __END__