You must have server-side includes turned on for this to work. Name your page with a .shtml extension or set execute permission on (depending on your web server configuration).
To insert a counter, add the following HTML:
You are visitor number <!--#exec cmd="../cgi-bin/counter.pl" -->
and put counter.pl in cgi-bin.
Or you could write the program in C++. To compile counter.cpp:
g++ counter.cpp -o counter