diff --git a/ChangeLog b/ChangeLog
index e05c208e..796cf588 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-01-30  Rene Liebscher <R.Liebscher@gmx.de>
+
+	* configure.ac: fixed detection of yylex_destroy availability
+	by checking the version number of flex
+
 2012-01-30  Joerg Wunsch <j.gnu@uriah.heep.sax.de>
 
 	* lexer.l: Replace the old, now-defunct #define YY_NO_UNPUT by
diff --git a/configure.ac b/configure.ac
index 6d909163..5bb71d3e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -37,6 +37,7 @@ AM_CONFIG_HEADER(ac_cfg.h)
 # Checks for programs.
 AC_PROG_CC
 AC_PROG_INSTALL
+AC_PROG_SED
 AC_PROG_YACC
 AC_PROG_LEX
 AC_PROG_RANLIB
@@ -44,7 +45,26 @@ AH_TEMPLATE([HAVE_YYLEX_DESTROY],
             [Define if lex/flex has yylex_destroy])
 # flex should have this
 if test "x$LEX" == xflex; then
-   AC_DEFINE([HAVE_YYLEX_DESTROY])
+   AC_MSG_CHECKING([whether yylex_destroy is generated by flex])
+   flex_version=`$LEX -V -v --version 2>/dev/null | $SED -e 's/^.* //'`
+   case $flex_version in
+       [[0-1].*)]
+           AC_MSG_RESULT([version $flex_version => no])
+           ;;
+       [2.[0-4].*)]
+           AC_MSG_RESULT([version $flex_version => no])
+           ;;
+       [2.5.[0-8])]
+           AC_MSG_RESULT([version $flex_version => no])
+           ;;
+       [2.5.[0-8][A-Za-z]*)]
+           AC_MSG_RESULT([version $flex_version => no])
+           ;;
+       *)
+           AC_MSG_RESULT([version $flex_version => yes])
+           AC_DEFINE([HAVE_YYLEX_DESTROY])
+           ;;
+   esac
 fi
 
 dnl Makefile.am:77: compiling `config_gram.c' with per-target flags requires `AM_PROG_CC_C_O' in `configure.ac'