use Fcntl qw/:flock/; use Data::Dumper; # Get stored config my $config = do( '/path/to/my_config.cfg') || {}; # . . . { # Serialize current config open my $fh, '>', '/path/to/my_config.cfg' or die $!; flock $fh, LOCK_EX; print $fh Dumper($config); }