open(PREF,"+< preffile") or die; while () { # if we see pref3 set to 0 if (/^pref3\t0$/) { # you need to rewind two chars to get # before the 0 and the newline , which # you've already gone past seek(PREF,-2,1) or die; # print a "9" in this spot print PREF "9"; # move forward one char past the newline # to continue reading. seek(PREF,1,1) or die; } } close PREF;