# untested seek $fh, 0, 0; # rewind to the start of the file print $fh $data; # Write the entire file close $fh;