in reply to Writing and modifying (change ordelete) a file

The short answer is that you have to rewrite the whole file. You can't modify stuff in place.

The slightly longer answer is that you can modify files in place, but you can't alter the length of the file at all.

Of course, Perl makes rewriting the whole file really easy, especially with the -i and -p command-line switches. Something like the following might do what you want:

perl -i -pe 's/(user):.*?:/$1:passwd:/' filename

*Woof*