open(FETCHMAILRC, '< .fetchmailrc') or die "Unable to open FMRC for reading. $!"; my $filecontents; while () { s/^here/$username\nhere/i; $filecontents .= $_; } close FETCHMAILRC or die "Close on FMRC died: $!"; # clobber file and open for writing open(FETCHMAILRC, "> .fetchmailrc') or die "Unable to open FMRC for writing. $!"; print FETCHMAILRC $filecontents; close FETCHMAILRC or die "Close on FMRC died: $!";