title: Why can't I concatenate and print the value returned by a function?
body: <p>I have a Perl program that calls a function, in this case <code>ref</code>, and checks the result. Specifically, I am testing that a variable is a hash reference. In that case, <code>ref</code> will return <code>'HASH'</code>. I tested it and it worked.</p>
  
  <p>Then I decided to log it, adding a <code>print</code> that displays the result of the same call, but it didn't work correctly. Here is a reduced version:</p>
  
  <pre><code>use strict;
  use warnings;
  
  my $book_ref = {};
  $book_ref-&gt;{'title'} = 'The Lord of the Rings';
  
  if (ref $book_ref eq 'HASH') {
      print "ref \$book_ref is a " . ref $book_ref . "\n";
  }
  
  print "Program is over\n";
  </code></pre>
  
  <p>To my surprise, this was the output:</p>
  
  <pre class="lang-none prettyprint-override"><code>ref $book_ref is a Program is over
  </code></pre>
  
  <p>And despite using <code>strict</code> and <code>warnings</code> there were neither errors nor warnings.<br>
  The call to <code>ref</code> is exactly the same (it's a copy and paste), but while it works correctly inside the <code>if</code> condition, <code>print</code> doesn't display anything, and actually seems to be interrupted, as the newline character is clearly skipped. Why does the behaviour change?</p>