title: How to append content of a file multiple times into one file in perl script
body: <p>I have a <code>sample.txt</code> file placed in directory say <code>/output_files</code> with some content in it.
  I want to create a new file say <code>sample_new.txt</code> and add the contents of <code>sample.txt</code> multiple times based on some condition.</p>
  <p>For example:</p>
  <ol>
  <li>Create new file <code>sample_new.txt</code></li>
  <li>For condition &lt;1..3&gt;</li>
  <li>Add the content of <code>sample.txt</code> into <code>sample_new.txt</code> files 3 times as the loop will run 3 times.</li>
  </ol>
  <p>I tried with below script, but it doesn't work:</p>
  <pre><code>my $sample_file = &quot;/output_files/sample.txt&quot;;
  my $new_sample_file  = &quot;/output_files/sample_new.txt&quot;;
            
  #For loop --running say 3 times
  open my $IN, '&lt;', $sample_file  or die $!;
  open my $OUT, '&gt;&gt;', $new_sample_file or die $!;
              
  while (&lt;$IN&gt;) {
      s/\b(hld_cf_id)\b/1234/g; #replacing some content while writing
      print {$OUT} $_;
  }
  close $OUT or die $!;
  #close loop;
  </code></pre>