use Win32::API; my $GetWindowsDirectory = new Win32::API( "KERNEL32","GetWindowsDirectoryA","PN","N" ); sub GetWindowsDirectory { my $buffer = "\0" x 255; $GetWindowsDirectory->Call($buffer,length $buffer); $buffer =~ tr/\0//d; return $buffer; }; print GetWindowsDirectory();