title: What is the actual Perl code that will mimic -pi inside the program?
body: <p>This seems redundant, running perl from a Perl script itself.</p>
  
  <pre><code>my $Pref = "&amp;*())(*&amp;^%$#@!"; 
  system("perl -pi -e 's|^SERVERNAME.*\$|SERVERNAME \"\Q$Pref\E\"|g' pserver.prefs");
  </code></pre>
  
  <p>What is the actual Perl code that will mimic -pi? I just want something that would work like sed on Perl, just as simple as can be.</p>
  
  <hr>
  
  <p>Based on Todd Gardner's site, it seems it basically just reads and writes all of the file, attempting to apply the regex to every line. The solution was a bit complex for a noob Perl user like me, so I dumbed it down using:</p>
  
  <pre><code>my $ftp = "/home/shared/ftp";
  my $backup = $ftp . ".bak";
  rename($ftp, $backup);
  open (FTP, "&lt;", $backup) or die "Can't open $backup: $!"; 
  open (FTP_OUT, "&gt;", $ftp) or die "Can't open $ftp: $!"; 
      while (&lt;FTP&gt;)
      {
          $_ =~ s|$panel_user \Q$panel_oldpass\E |$panel_user \Q$panel_newpass\E |g;
          print FTP_OUT $_;
      }
  close(FTP);
  close(FTP_OUT);
  </code></pre>
  
  <p>Is there anything wrong with using two opens? Should this be avoided or is it ok for a simple solution?</p>
  
  <p>I must admit, a system sed command is much more simple and cleaner.</p>