title: How do I add lines to the top and bottom of a file in Perl?
body: <p>I want to add a line to top and bottom of the file. I can do it following way. </p>
  
  <pre><code>open (DATA, "&lt;/usr/old") || die "cant open old\n"; #file to which line has to be added
  
  my @body=&lt;DATA&gt;;
  close(DATA);
  
  open (FILE, "&gt;/usr/new") || die "cant open new\n"; #file after stuff has been added
  
  print FILE "9   431";
  
  print FILE "\n";
  
  my $body=@body;
  
  for (my $i=0; $i&lt;$body;$i++){
  
      print FILE "$body[$i]";#not using for loop leads to addition of spaces in new file
  }
  
  print FILE "(3,((((1,4),(7,6)),(2,8)),5),9)";
  </code></pre>
  
  <p>Since I running for a large set of file this process will be time consuming. Does Perl has any specific functionality which used to add lines at top and bottom of a file?</p>