in reply to change x coordinate in pdb

You didn't show what an ATOM record or a TER is, so I expect it's not part of the problem that you need help with. Though I'll have to assume that you are dealing with text.

Use s// and m/// to identify and change parts of a line.

Use an "if" statement to determine if you are looking for the TER record or have passed it.

The file I/O is explained in any intro, but you might be interested in the -i command line option.