diff --git a/configure b/configure
index 7f2a0a0256a71d64ef659ca78c123f54cfe3d678..f315525e4b5086f0c9cf7826f16d604f249b11aa 100755
--- a/configure
+++ b/configure
@@ -14953,6 +14953,10 @@ fi
   # On most platforms, if perl.h is there then libperl.so will be too, but at
   # this writing Debian packages them separately.  There is no known reason to
   # waste cycles on separate probes for the Tcl or Python libraries, though.
+  # On some Red Hat platforms, the link attempt can fail if we don't use
+  # CFLAGS_SL while building the test program.
+  ac_save_CFLAGS=$CFLAGS
+  CFLAGS="$CFLAGS $CFLAGS_SL"
   pgac_save_LIBS=$LIBS
   LIBS="$perl_embed_ldflags"
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libperl" >&5
@@ -14982,6 +14986,7 @@ fi
 rm -f core conftest.err conftest.$ac_objext \
     conftest$ac_exeext conftest.$ac_ext
   LIBS=$pgac_save_LIBS
+  CFLAGS=$ac_save_CFLAGS
   CPPFLAGS=$ac_save_CPPFLAGS
 fi
 
diff --git a/configure.in b/configure.in
index ab640115fb15bf2e90dee685a754de6b3fc6c437..decb070e5b3b300463e38cde53770c9708f625bd 100644
--- a/configure.in
+++ b/configure.in
@@ -1980,6 +1980,10 @@ if test "$with_perl" = yes; then
   # On most platforms, if perl.h is there then libperl.so will be too, but at
   # this writing Debian packages them separately.  There is no known reason to
   # waste cycles on separate probes for the Tcl or Python libraries, though.
+  # On some Red Hat platforms, the link attempt can fail if we don't use
+  # CFLAGS_SL while building the test program.
+  ac_save_CFLAGS=$CFLAGS
+  CFLAGS="$CFLAGS $CFLAGS_SL"
   pgac_save_LIBS=$LIBS
   LIBS="$perl_embed_ldflags"
   AC_MSG_CHECKING([for libperl])
@@ -1991,6 +1995,7 @@ if test "$with_perl" = yes; then
     [AC_MSG_RESULT(no)
      AC_MSG_ERROR([libperl library is required for Perl])])
   LIBS=$pgac_save_LIBS
+  CFLAGS=$ac_save_CFLAGS
   CPPFLAGS=$ac_save_CPPFLAGS
 fi