open my $fh, '>', $file or die $!; flock $fh, LOCK_EX or die $!; seek $fh, 0, SEEK_END or die $!; print $fh $json; close $fh;