If you insist on using a "flat file", which I assume means line-delimited records in an ordinary file, then the fastest (programmers') way to delete or insert a record is to read the file into an array (Perl will read it automatically into your array with line-delimiters as default), switch it in your script with the whole file in MEM and rewrite the file. Of course, this is not the optimal solution. The optimal solution involves moving (on average) 50% of all data sets in the file to delete and none to append. To delete, find the line where you want the deletion to begin/end and copy the rest of the file "up". Another solution would be to comment it out in some manner and "optimize" you crappy database on a cron cycle by deleting comments from the file every so often. Edit is yet more complicated since it may involve reducing or enlarging the file depending on how much input is given. Of course, as the others said, this is very strange limiting situation and it would be extraordinarily easy to convert your text file to a form of
AnyDBM_File, which is the recommended solution if you're not running a dbengine. Since this is CGI, as you mentioned, you'll want to be careful what the user passes you- perhaps max line lengths, valid chars, etc.