Using `sed`:
sed 's/^\(ServerName\)$/\1 www.mydomain.com/' file.txt
The captured group, `\(ServerName\)` is used in the replacement pattern as `\1`.
Editing the file in place, with backup, assuming the GNU, `ssed`, busybox or some BSD implementations of `sed`:
sed -i.bak 's/^\(ServerName\)$/\1 www.mydomain.com/' file.txt
The original file will be kept as `file.bak` and the modified file will be `file.txt.bak`.
Editing in place, without backup (GNU, `ssed` or `busybox` only):
sed -i 's/^\(ServerName\)$/\1 www.mydomain.com/' file.txt
(for BSDs, use `sed -i '' 's/...`).
* * *
Even shorter, without any captured group:
sed -i 's/^ServerName$/& www.mydomain.com/' file.txt
Here `&` will be replaced by the match.