yet another way (not necessarily the best) would be Cache::FileCache (useful for many other things such as caching database query results). One downside (or upside) is you don't (readily--i think it throws it under /tmp/ somewhere) have the filename, so can't do "cat counter.txt" to check it.
use Cache::FileCache;
my $cache = new Cache::FileCache( { namespace=>"my_program", auto_pu
+rge_on_get=>1 } );
my $cacheKey = 'ct';
my $value = $cache->get( $cacheKey ) || 0;
$value++;
$cache->set( $cacheKey, $value, $EXPIRES_NEVER );