diff -Naur grep/src/grep.c grep_new/src/grep.c
--- grep/src/grep.c	2005-04-22 20:14:31.000000000 +0200
+++ grep_new/src/grep.c	2005-04-22 20:14:18.000000000 +0200
@@ -36,6 +36,10 @@
 # include <wchar.h>
 # include <wctype.h>
 #endif
+#ifdef HAVE_LANGINFO_CODESET
+# include <langinfo.h>
+#endif
+
 #include <stdio.h>
 #include "system.h"
 #include "getopt.h"
@@ -157,6 +161,9 @@
 int match_words;
 int match_lines;
 unsigned char eolbyte;
+#ifdef MBS_SUPPORT
+int using_utf8;
+#endif
 
 /* For error messages. */
 /* The name the program was run with, stripped of any leading path. */
@@ -1317,6 +1324,24 @@
   return opt;
 }
 
+#ifdef MBS_SUPPORT
+
+static int
+mb_check_utf8(void)
+{
+#if defined(HAVE_LANGINFO_CODESET)
+  if (strcmp (nl_langinfo (CODESET), "UTF-8") == 0)
+    return 1;
+#elif defined (HAVE_SETLOCALE)
+  if (strstr (setlocale(LC_CTYPE, 0), "utf8") ||
+      strstr (setlocale(LC_CTYPE, 0), "UTF8"))
+    return 1;
+#endif
+  return 0;
+}
+ 
+#endif /* MBS_SUPPORT */
+
 int
 main (int argc, char **argv)
 {
@@ -1387,6 +1412,9 @@
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 #endif
+#ifdef MBS_SUPPORT
+  using_utf8 = mb_check_utf8();
+#endif
 
   atexit (close_stdout);
 
diff -Naur grep/src/grep.h grep_new/src/grep.h
--- grep/src/grep.h	2005-04-22 20:14:46.000000000 +0200
+++ grep_new/src/grep.h	2005-04-22 20:14:18.000000000 +0200
@@ -40,3 +40,7 @@
 extern int match_words;		/* -w */
 extern int match_lines;		/* -x */
 extern unsigned char eolbyte;	/* -z */
+
+#ifdef MBS_SUPPORT
+extern int using_utf8;		/* utf8 optimization */
+#endif
diff -Naur grep/src/search.c grep_new/src/search.c
--- grep/src/search.c	2005-04-22 20:14:40.000000000 +0200
+++ grep_new/src/search.c	2005-04-22 20:14:18.000000000 +0200
@@ -666,10 +666,9 @@
 #else
   int e;
   char const *ep;
-  char *re = xmalloc (4 * size + 7);
-  int flags = PCRE_MULTILINE | (match_icase ? PCRE_CASELESS : 0);
+  char *re, *n;
+  int flags;
   char const *patlim = pattern + size;
-  char *n = re;
   char const *p;
   char const *pnul;
 
@@ -677,6 +676,18 @@
   if (eolbyte != '\n')
     error (2, 0, _("The -P and -z options cannot be combined"));
 
+  /* PCRE_CASELESS does not work under PCRE_UTF8 */
+  if (match_icase && using_utf8)
+    {
+      error (0, 0, _("warning: %s: %s\n"), "PCRE", 
+	     _("PCRE_CASELESS does not work under PCRE_UTF8"));
+    }
+
+  flags = PCRE_MULTILINE |
+    (match_icase ? PCRE_CASELESS : 0) |
+    (using_utf8 ? PCRE_UTF8 : 0);
+
+  n = re = xmalloc (4 * size + 7);
   *n = '\0';
   if (match_lines)
     strcpy (n, "^(");
