title: How to output binary files in Perl?
body: <p>I want to be able to output <code>0x41</code>, and have it show up as <code>A</code>.</p>
  
  <p>This is what I have tried so far:</p>
  
  <pre><code>my $out;
  open $out, "&gt;file.txt" or die $!;
  binmode $out;
  print $out 0x41;
  close $out;
  </code></pre>
  
  <p>It outputs <code>65</code> instead of <code>A</code> in the resulting file. This is not what I want.</p>
  
  <p>I also have read <a href="https://stackoverflow.com/questions/1464195/how-can-i-create-a-binary-file-in-perl">this similar question</a>, but I wouldn't transfer the answer over. <code>pack</code> a short results to 2 bytes instead of 1 byte.</p>