Dave.
#!/usr/bin/perl
use CGI;
$query=CGI::new();
$url=$query->param("url");
open (FP, ">>clicks.log");
print FP "$url\n";
close(FP);
print "Location: $url\n\n";
If you link to this script in the form <a href="script.cgi?url=http://www.webmasterworld.com">foo</a> it'll log that click and then redirect to the url specified.
Counting the clicks would then be a matter of checking how many times each url shows up in the log file.
Dave.