use strict; my $newcontent="My camel has been bitten by a rather large flea. Please call a vet."; my $input="camel.cgi"; my $tempfile="/tmp/camel.$$"; open TARGET, "<$input" or die "Blerch: $!\n"; open TEMP, ">/$tempfile" or die "Hcerlb: $!\n"; while () { # check for your cue: could be a running counter to # keep track of lines read, could be a regexp, could # be just about anything else. Let's assume the check # sets $ship_ahoy when you need to add lines. if $ship_ahoy {print TEMP $newcontent} print TEMP; } close INPUT; close TMP; rename $tempfile $input or die "Hrlecb:$!\n"; print "Beware, this is untested code, and could definitely do with more robust error checking!\n";