diff --git a/SOURCES/perl-5.31.5-PATCH-gh-17218-memory-leak.patch b/SOURCES/perl-5.31.5-PATCH-gh-17218-memory-leak.patch
new file mode 100644
index 0000000..abb6223
--- /dev/null
+++ b/SOURCES/perl-5.31.5-PATCH-gh-17218-memory-leak.patch
@@ -0,0 +1,22 @@
+From 70f089724b15d1b2ed9264f277454aa559d50232 Mon Sep 17 00:00:00 2001
+From: Karl Williamson <khw@cpan.org>
+Date: Fri, 15 Nov 2019 15:01:15 -0700
+Subject: [PATCH] PATCH: gh#17218 memory leak
+
+Indeed, a variable's ref count was not getting decremented.
+---
+ regcomp.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/regcomp.c b/regcomp.c
+index ddac290d2bf0..de4f6f24dac8 100644
+--- a/regcomp.c
++++ b/regcomp.c
+@@ -17602,6 +17602,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
+ 
+                 /* Likewise for 'posixes' */
+                 _invlist_union(posixes, cp_list, &cp_list);
++                SvREFCNT_dec(posixes);
+ 
+                 /* Likewise for anything else in the range that matched only
+                  * under UTF-8 */
diff --git a/SPECS/perl.spec b/SPECS/perl.spec
index 4c0f265..b97a3d5 100644
--- a/SPECS/perl.spec
+++ b/SPECS/perl.spec
@@ -81,7 +81,7 @@ License:        GPL+ or Artistic
 Epoch:          %{perl_epoch}
 Version:        %{perl_version}
 # release number must be even higher, because dual-lived modules will be broken otherwise
-Release:        420%{?dist}
+Release:        421%{?dist}
 Summary:        Practical Extraction and Report Language
 Url:            http://www.perl.org/
 Source0:        http://www.cpan.org/src/5.0/perl-%{perl_version}.tar.bz2
@@ -311,6 +311,9 @@ Patch94:       perl-5.26.3-CVE-2020-10878.patch
 Patch95:       perl-5.26.3-Net-Ping-carp-not-croak-on-most-name-lookup-failures.patch
 Patch96:       perl-5.26.3-Net-Ping-Fix-_resolv-return-value.patch
 
+# Fix a memory leak when compiling a regular expression with a non-word class,
+# GH#17218, in upstream after 5.31.5
+Patch97:       perl-5.31.5-PATCH-gh-17218-memory-leak.patch
 
 # Link XS modules to libperl.so with EU::CBuilder on Linux, bug #960048
 Patch200:       perl-5.16.3-Link-XS-modules-to-libperl.so-with-EU-CBuilder-on-Li.patch
@@ -2926,6 +2929,7 @@ Perl extension for Version Objects
 %patch94 -p1
 %patch95 -p1
 %patch96 -p1
+%patch97 -p1
 %patch200 -p1
 %patch201 -p1
 
@@ -2988,6 +2992,7 @@ perl -x patchlevel.h \
     'RHEL Patch93: Fix CVE-2020-10543' \
     'RHEL Patch94: Fix CVE-2020-10878' \
     'RHEL Patch95: Fix Net-Ping _resolv return value on failing DNS name lookup (bug #1973030)' \
+    'RHEL Patch97: Fix a memory leak when compiling a regular expression with a non-word class (GH#17218)' \
     'Fedora Patch200: Link XS modules to libperl.so with EU::CBuilder on Linux' \
     'Fedora Patch201: Link XS modules to libperl.so with EU::MM on Linux' \
     %{nil}
@@ -5275,6 +5280,10 @@ popd
 
 # Old changelog entries are preserved in CVS.
 %changelog
+* Mon Oct 18 2021 Jitka Plesnikova <jplesnik@redhat.com> - 4:5.26.3-421
+- Fix a memory leak when compiling a regular expression with a non-word
+  class (bug #2014981)
+
 * Thu Jun 17 2021 Jitka Plesnikova <jplesnik@redhat.com> - 4:5.26.3-420
 - Fix _resolv return value in Net-Ping (bug #1973030)