Parity with original Perl script