If this is running under Windows, extra bytes are probably being added when you write your decoded binary data from the $fContent variable to OFILE. If this is the case, you could fix it by adding the line binmode OFILE; immediately after lines which begin with open ( OFILE,...