diff --git a/varnish.module b/varnish.module
index 2097ee3..34d5f33 100644
--- a/varnish.module
+++ b/varnish.module
@@ -146,11 +146,26 @@ function varnish_user($op, &$edit, &$account, $category = NULL) {
  * You may also safely call this function directly with an array of local urls to purge.
  */
 function varnish_expire_cache($paths) {
+  // Set a length limit per regex as Varnish will hang up after 8192 bytes of command
+  $length_limit = 7500;
+
   $host = _varnish_get_host();
   $base = base_path();
-  $purge = implode('$|^'. $base, $paths);
-  $purge = '^'. $base . $purge .'$';
-  varnish_purge($host, $purge);
+
+  // Arrange $purges into chunks of no more than $length_limit
+  while (!empty($purges)) {
+    $length_bytes = 0;
+    $purges_chunk = array();
+    do {
+      $purge_path = array_unshift($purges);
+      $purges_chunk[] = $purge_path;
+      $length_bytes += strlen($purge_path); // intentional strlen() to get byte length, not charlength
+    }
+    while ($length_bytes <= $length_limit && !empty($purges));
+
+    $purge = '^'.$base.implode('$|^'.$base , $purges_chunk).'$';
+    varnish_purge($host, $purge);
+  }
 }
 
 /**
