$function = Win32::API->new('NSLClientLibrary', 'XYZDecrypt', 'PPP', 'I'); sub call_function { my ($value, $key, $encrypted) = @_; # Here we pad $value to the expected length, to avoid a buffer overrun # I guess that the result is at most as long as the encrypted string $value = ' ' x length $encrypted; $function->( $value, $key, $encrypted ); $value =~ s!\0.*!!; # we assume that the first \0 returned indicates end of the string return $value };