diff --git a/Makefile b/Makefile
index fb6ce98..b459f06 100644
--- a/Makefile
+++ b/Makefile
@@ -150,6 +150,9 @@ ADDLIB =
 DEFINE =
 SILENT_DEFINE =
 
+ifeq ($(_LIB),)
+_LIB	        := lib
+endif
 
 #### CPU dependant optimizations
 # Some CFLAGS are set by default depending on the target CPU. Those flags only
@@ -522,7 +525,7 @@ PCREDIR	        := $(shell pcre-config --prefix 2>/dev/null || echo /usr/local)
 endif
 ifeq ($(USE_STATIC_PCRE),)
 OPTIONS_CFLAGS  += -DUSE_PCRE $(if $(PCREDIR),-I$(PCREDIR)/include)
-OPTIONS_LDFLAGS += $(if $(PCREDIR),-L$(PCREDIR)/lib) -lpcreposix -lpcre
+OPTIONS_LDFLAGS += $(if $(PCREDIR),-L$(PCREDIR)/$(_LIB)) -lpcreposix -lpcre
 endif
 BUILD_OPTIONS   += $(call ignore_implicit,USE_PCRE)
 endif
@@ -534,7 +537,7 @@ ifeq ($(PCREDIR),)
 PCREDIR         := $(shell pcre-config --prefix 2>/dev/null || echo /usr/local)
 endif
 OPTIONS_CFLAGS  += -DUSE_PCRE $(if $(PCREDIR),-I$(PCREDIR)/include)
-OPTIONS_LDFLAGS += $(if $(PCREDIR),-L$(PCREDIR)/lib) -Wl,-Bstatic -lpcreposix -lpcre -Wl,-Bdynamic
+OPTIONS_LDFLAGS += $(if $(PCREDIR),-L$(PCREDIR)/$(_LIB)) -Wl,-Bstatic -lpcreposix -lpcre -Wl,-Bdynamic
 BUILD_OPTIONS   += $(call ignore_implicit,USE_STATIC_PCRE)
 endif
 
diff --git a/include/common/regex.h b/include/common/regex.h
index 60c7f42..3034455 100644
--- a/include/common/regex.h
+++ b/include/common/regex.h
@@ -27,6 +27,13 @@
 #ifdef USE_PCRE
 #include <pcre.h>
 #include <pcreposix.h>
+
+/* if pcre is old and does not support JIT, fallback to no JIT mode. */
+#ifndef PCRE_STUDY_JIT_COMPILE
+#define PCRE_STUDY_JIT_COMPILE 0
+#define pcre_free_study pcre_free
+#endif
+
 #else
 #include <regex.h>
 #endif
diff --git a/include/types/acl.h b/include/types/acl.h
index bf5537f..15fcdb3 100644
--- a/include/types/acl.h
+++ b/include/types/acl.h
@@ -213,7 +213,12 @@ struct acl_pattern {
 	union {
 		void *ptr;              /* any data */
 		char *str;              /* any string  */
+#ifdef USE_PCRE
+		pcre *regex;            /* a compiled regex */
+		pcre_extra *reg_extra;  /* a study result of a compiled regex */
+#else
 		regex_t *reg;           /* a compiled regex */
+#endif
 	} ptr;                          /* indirect values, allocated */
 	void(*freeptrbuf)(void *ptr);	/* a destructor able to free objects from the ptr */
 	int len;                        /* data length when required  */
diff --git a/src/acl.c b/src/acl.c
index cba89ab..4461944 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -533,7 +533,11 @@ int acl_match_reg(struct sample *smp, struct acl_pattern *pattern)
 	old_char = smp->data.str.str[smp->data.str.len];
 	smp->data.str.str[smp->data.str.len] = 0;
 
+#ifdef USE_PCRE
+	if (pcre_exec(pattern->ptr.regex, pattern->ptr.reg_extra, smp->data.str.str, smp->data.str.len, 0, 0, NULL, 0) == 0)
+#else
 	if (regexec(pattern->ptr.reg, smp->data.str.str, 0, NULL, 0) == 0)
+#endif
 		ret = ACL_PAT_PASS;
 	else
 		ret = ACL_PAT_FAIL;
@@ -900,12 +904,37 @@ acl_parse_strcat(const char **text, struct acl_pattern *pattern, int *opaque, ch
 /* Free data allocated by acl_parse_reg */
 static void acl_free_reg(void *ptr)
 {
+#ifdef USE_PCRE
+	pcre_free_study((pcre_extra *)(ptr + sizeof(pcre *)));
+	pcre_free((pcre *)ptr);
+#else
 	regfree((regex_t *)ptr);
+#endif
 }
 
 /* Parse a regex. It is allocated. */
 int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque, char **err)
 {
+#ifdef USE_PCRE
+	pcre *preg;
+	pcre_extra *preg_extra;
+	int icase;
+
+	icase = (pattern->flags & ACL_PAT_F_IGNORE_CASE) ? PCRE_CASELESS : 0;
+
+	preg = pcre_compile(*text, PCRE_NO_AUTO_CAPTURE | icase, NULL, NULL, NULL);
+	if (!preg)
+		return 0;
+
+        preg_extra = pcre_study(preg, PCRE_STUDY_JIT_COMPILE, NULL);
+	if (!preg_extra) {
+		pcre_free(preg_extra);
+		return 0;
+	}
+
+	pattern->ptr.regex = preg;
+	pattern->ptr.reg_extra = preg_extra;
+#else
 	regex_t *preg;
 	int icase;
 
@@ -924,6 +953,7 @@ int acl_parse_reg(const char **text, struct acl_pattern *pattern, int *opaque, c
 	}
 
 	pattern->ptr.reg = preg;
+#endif
 	pattern->freeptrbuf = &acl_free_reg;
 	return 1;
 }
