Here is one way of doing it on Windows:
use strict;
use Win32::OLE qw(in);
my $WMI = Win32::OLE->GetObject("winmgmts:")
or die ("Could not create WMI object.");
my $OS_Col = $WMI->InstancesOf('Win32_OperatingSystem')
or die ("Could not get OS instances.");
foreach my $OS (in $OS_Col) {
printf "Free Physical Memory: %10u kB\n", $OS->{FreePhysicalMemor
+y};
printf "Free Virtual Memory: %10u kB\n", $OS->{FreeVirtualMemory
+};
printf "Total Virtual Memory: %10u kB\n", $OS->{TotalVirtualMemor
+ySize};
printf "Total Visible Memory: %10u kB\n", $OS->{TotalVisibleMemor
+ySize};
}