my $state_mutex = Mutex->new( path => "/tmp/state.lock" ); $state_mutex->enter( sub { # Unable to obtain exclusive lock, then append pending inserts # to a state file. Otherwise, read pending items, insert into DB, # then unlink or empty the state file. } );