open F, "+< somefile" or die ...; flock F, LOCK_EX or die ...; truncate F, 0 or die ...; # Now write F close F;