diff --git a/meson.build b/meson.build
index 87437960bc..be87ef6950 100644
--- a/meson.build
+++ b/meson.build
@@ -993,21 +993,15 @@ if not perlopt.disabled()
     # Config's ccdlflags and ldflags.  (Those are the choices of those who
     # built the Perl installation, which are not necessarily appropriate
     # for building PostgreSQL.)
-    ldopts = run_command(perl, '-MExtUtils::Embed', '-e', 'ldopts', check: true).stdout().strip()
-    undesired = run_command(perl_conf_cmd, 'ccdlflags', check: true).stdout().split()
-    undesired += run_command(perl_conf_cmd, 'ldflags', check: true).stdout().split()
-
-    perl_ldopts = []
-    foreach ldopt : ldopts.split(' ')
-      if ldopt == '' or ldopt in undesired
-        continue
-      endif
-
-      perl_ldopts += ldopt.strip('"')
-    endforeach
-
+    ldopts = run_command(perl, '-MExtUtils::Embed', '-e', '*ExtUtils::Embed::_ldflags = *Extutils::Embed::_ccdlflags = sub { return q[]; }; ldopts',
+                         check: true).stdout().strip()
+    # avoid use of " char in this perl mini-program to avoid possibly
+    # confusing the Windows command processor
+    perl_ldopts = run_command(perl, '-MEnglish', '-e',
+                              'my $arg = shift; while ($arg =~ /\S/) { if ($arg =~ /^\s*([^\042 ]+)(?![\042])/) { print qq[$1\n]; $arg = $POSTMATCH;} elsif ($arg =~ /^\s*\042([^\042]+)\042/) { print qq[$1\n]; $arg = $POSTMATCH;} }',
+                              '--', ldopts, check: true).stdout().strip().split('\n')
     message('LDFLAGS recommended by perl: "@0@"'.format(ldopts))
-    message('LDFLAGS for embedding perl: "@0@"'.format(' '.join(perl_ldopts)))
+    message('LDFLAGS for embedding perl:\n"@0@"'.format('\n'.join(perl_ldopts)))
 
     perl_dep_int = declare_dependency(
       compile_args: perl_ccflags,
