diff --git a/tests/Makefile.am b/tests/Makefile.am
index e162bc767511d87c24d24f6aceade63ebf7e9761..27d0f76ee4acafb923b499f1b97befb6b9197001 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1464,7 +1464,7 @@ check-matlab-ols: $(M_OLS_TRS_FILES)
 %.m.trs %.m.log: %.mod
 	@echo "`tput bold``tput setaf 8`MATLAB: $(CURDIR)/$*... `tput sgr0`"
 # The while loop is a workaround for this glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19329 (should be fixed in glibc 2.34, likely included in Debian “bookworm” 12)
-	@while ! [ -f $*.m.trs ] || head -1 $*.m.log | egrep -q '^Inconsistency detected by ld.so'; \
+	@while ! [ -f $*.m.trs ] || head -1 $*.m.log | grep -E -q '^Inconsistency detected by ld.so'; \
 	do \
 	DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(CURDIR)" FILESTEM="$*" \
 		$(MATLAB)/bin/matlab $(MATLAB_BATCH_OPTIONS) run_test_matlab > $*.m.log 2>&1 || \
@@ -1483,7 +1483,7 @@ check-matlab-ols: $(M_OLS_TRS_FILES)
 %.m.trs %.m.log : %.m
 	@echo "`tput bold``tput setaf 8`MATLAB: $(CURDIR)/$*... `tput sgr0`"
 # The while loop is a workaround for this glibc bug: https://sourceware.org/bugzilla/show_bug.cgi?id=19329 (should be fixed in glibc 2.34, likely included in Debian “bookworm” 12)
-	@while ! [ -f $*.m.trs ] || head -1 $*.m.log | egrep -q '^Inconsistency detected by ld.so'; \
+	@while ! [ -f $*.m.trs ] || head -1 $*.m.log | grep -E -q '^Inconsistency detected by ld.so'; \
 	do \
 	DYNARE_VERSION="$(PACKAGE_VERSION)" TOP_TEST_DIR="$(CURDIR)" \
 		$(MATLAB)/bin/matlab $(MATLAB_BATCH_OPTIONS) $* > $*.m.log 2>&1 || \