use threads::shared; ... my $sem :shared; ... { # some scope (as tight as possible) lock $sem; print ...; }