The following Perl code ..
if ($^O eq \"MSWin32\") {
use Win32;
This code will work in all situations, and also performs the load at compile-time, as other modules you are building might depend on it:
BEGIN {
if ($^O eq "MSWin32")
{
require Module;
Module->import(); # assuming you would not be passing arguments to "use Module"
}
}
This is because use Module (qw(foo bar))
is equivalent to BEGIN { require Module; Module->import( qw(foo bar) ); }
as described in perldoc -f use.
(EDIT, a few years later...)
This is even better though:
use if $^O eq "MSWin32", Module;
Read more about the if
pragma here.