Creating and porting Perl CGIs in Windows9x/XP/2000

This is an introduction to creating and porting (from UNIX) Perl CGIs in the Windows 95/XP platform. Basic Perl CGI development is introduced and the issues of adapting Perl CGIs written for Unix to run in Windows9x/XP/2000 are discussed.

Creating CGIs with Perl

Creating CGIs with Perl  is comprised of three parts: (a) use  of a CGI library, (b) development of a Perl script, and (c) use Perl to print HTML pages. Lets see each one in turn.

  1. Use of a CGI library
  2. There are a variety of  libraries used in Perl scripts, most of them stored in Perl/lib. We call a library in a perl script by requiring (require  or using (use  A very common  library used in Perl scripts is ,  compatible with Perl 4 and above.

    We have seen some functions of  the  previously.  Lets take a closer look at version 2.18.

  3. Development of a Perl script
  4. Scripts are created as seen in Essential Perl . Some minor modifications are needed however, for some characters used in Perl  that also have a HTML meaning, and vice-versa. Typically the use of   " (quotes), \  (backlash and . (dot)  in CGIs are a source of problems for beginners. these characters need to be "escaped" by the use of a \ (backslash) to avoid this problem. They  also create problems in regular Perl scripts  For example:

  5. Using Perl to print HTML pages
  6. A large part of most scripts is only a series of print statements, or similar, writing HTML pages to be send to the CGI requester as a reply.  A simple solution for creating the HTML part of the scripts is to create the HTML page(s)  using an editor and converting it (them) to Perl code. There are different ways to do it. Here are two of them:

Porting Perl CGIs from Unix to Windows 9x/XP/2000

The vast majority of  Perl CGIs have been written for UNIX, not Windows. In the process of porting  Perl CGIs we need to be aware of three types of issues: (a) difference in file systems, (b) system  commands that only exist in UNIX, and (c) Perl features not converted to Windows 95/XP.

  1. Difference in File Systems
  2. The detailed discussion of UNIX and Windows file systems are beyond the scope of this tutorial. If you "need" to know more see a summary and a detailed reference for UNIX .

    UNIX does not use a drive letter like Windows, and directories and file full names are separated by / (slash) not \ (backslash) as Windows do. So a file name in UNIX would be /usr/project/home.html while in Windows we would have something like c:\usr\project\home.html.  If you have wondered why URLs are writen like now you know why -- the Internet was developed using UNIX terminology and conventions.

    File names in UNIX do not have required extensions like in Windows.  job is a valid name in UNIX and both Windows 95/XP/2000 can also support file names without extensions, but not DOS. Long file names are also supported. But, in UNIX the . (dot) is a character as any other in the file name -- e.g.  The consequence is that dir * in UNIX is equivalent to dir *.* in Windows.

  3. System commands that only exist in UNIX
  4. A more serious issue is one related to commands that only exist in UNIX with no equivalent in Windows. Classical problems in CGIs  are: sendmail, crypt and  grep.

    Sendmail is a very sophisticated mail system that is a command in UNIX, not a separated program (refer to the class in forms and CGIs for our discussion of instead in Windows).

    Crypt allows the encription of files and particularly passwords and it is also a native command in UNIX.  Perl 5  for Win32 build 110 and above includes it --  example: $passwd = crypt(test99, substr($passwd, 0, 2));  -- where test99 is the non-encrypted password value.  You can save the password to a file and later compare with input. See a very simple example in

    Grep is a very advanced search tool  frequently used for HTML page counters, search engines, etc. There is no generic substitute, you can either use an UNIX port of grep for Windows, or write specific scripts or programs to perform a given function.
    There are, without doubt, other commands that are source of problems, like cron, date (different format), etc,  but the three above commands account for the majority of the port problems.

  5. Perl features not converted to Windows 95/XP/2000
  6. ActiveState has been pretty active in porting most features of Perl from UNIX to Win32. Most Perl 5 commands and libraries are now working in Win32. There are still some exceptions as listed in the release notes.

    If you try to port a Perl command or library, and it does not seem to work, I suggest that you read the release notes of the build you are using.  Also please note that is no longer part of the standard distribution of Perl for Win32.  Remember to download a new version of  and add to Perl/lib in order to provide compatibility with many scripts available on the Web.

This page is maintained by Al Bento who can be reached at This page was last updated on October 5, 2004. Although we will attempt to keep this information accurate, we can not guarantee the accuracy of the information provided.