use Tie::File; sub Counter ($) { my @array; my $o = tie @array, 'Tie::File', shift || return undef; $o->flock; $array[0]++; }