in reply to modifying a line in a file with some restrictions

...without using a module, and without putting the whole file into an array or something? ... Um, well... you are already reading the whole file into a scalar, and modifying that scalar, so you're close; this get you rest of the way (mostly -- but it's not tested):
$/ = undef; $filename = "$root/content/topics/$get{'topic'}"; open( TOPIC, "+<", $filename ) or die "Unable to read/write $filename\ +n"; $_ = <TOPIC>; if( /^\Q$get{'post'}\E/ ) { s/.*\n$/$post/m; } seek( TOPIC, 0, 0 ); # rewind to start of file print TOPIC; close TOPIC;
Since this seems to be part of a CGI process, we have to raise the standard "issues"... You need to apply some form of file locking, because two browsers could try to make distinct changes on the same file at the same time. You probably need to include taint checking (at least), or employ some reasonably secure way of specifying the name of the file to be opened and over-written. (I've added the "easy" part: the contents of $get{post} need to be enclosed within the "quote-meta" operators \Q...\E, in case it happens to include things like period, plus, asterisk, parens, brackets, and so on, which might cause a run-time error or mis-match.)