open FH, '+) { s/2/two\nhi hello/; $temp .= $_; } seek(FH, 0, 0); print FH $temp; truncate(FH, tell(FH)); close(FH);