use strict; use constant GENERIC_READ => 0x80000000; use constant OPEN_EXISTING => 3; use constant FILE_ATTRIBUTE_NORMAL => 0x00000080; use Win32::API; use Win32::API::Struct; Win32::API::Struct->typedef(SECURITY_ATTRIBUTES => qw{  DWORD nLength  LPVOID lpSecurityDescriptor  BOOL bInheritHandle }); Win32::API->Import('kernel32', 'HANDLE CreateFile(LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)'); Win32::API->Import('kernel32', 'DWORD GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)'); Win32::API->Import('kernel32', 'BOOL CloseHandle(HANDLE hObject)'); sub GetOpenFileSizeWin {   my ($file) = @_;   my $handle = 0; my $size = 0;   $handle = CreateFile($file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);   if($handle)   { $size = GetFileSize($handle, 0); CloseHandle($handle);   } return $size; }