open(FH, "+< filename.txt") || die "$!"; #open the file for read/write flock(FH, LOCK_EX); # get an exclusive lock seek(FH, 0, SEEK_SET); # move filepointer to beginning of file read(FH, $scalar, $bytes); # what if I want the whole thing, no matter how many bytes? # do something with # $scalar here seek(FH, 0, SEEK_SET); # move filepointer to beginning of file (is this correct syntax for this?) print FH $scalar; # print at beginning of file, clobbering old data truncate(FH, tell(FH)); # truncate any data beyond where we've written (is this correct as well?) close(FH); # close the file