# update shared counters use threads; use threads::shared; # needed for shared variables my $TotalsLock:shared; # variable to be the lock my $MsgCnt:shared; my $TotalBytes:shared; .... { lock $TotalsLock; # I have locked access $MsgCnt++; $TotalBytes += $bytesThisemail; } # lock released at end of enclosing scope #### # update shared counters use threads; use threads::shared; # needed for shared variables my $TotalsLock:shared; # variable to be the lock my $MsgCnt:shared; my $TotalBytes:shared; .... { lock $TotalsLock; # I have locked access print "Activity Totals: $MsgCnt $TotalBytes]n"; } # lock released at end of enclosing scope