open my $fh, "<", "myfile" or die; my $check_value = 0; while (1) { my $buf; my $cnt = read $fh, $buf, 4; if (!defined $cnt) { die("Error while reading from input file: $!"); } elsif ($cnt==0) { last; } elsif ($cnt%4) { die("File or chunk does not seem to have a length that's a multiple of 4 bytes"); } my $val = unpack("L",$buf); $check_value ^= $val; my $rotate = $check_value & 0x80000000; $check_value = ($check_value << 1 ) & 0xffffffff; if ($rotate) { $check_value |= 0x01; } }