What would be the best way to open a text file, find a string, delete it, perform an action then add the string back to the text file? !!!

ie

open text file
find "wibble"
if it exists - delete it
close text file

perform some action

open text file
add "wibble"
close text file

Any ideas people?
Simon