diff --git a/varnish.admin.inc b/varnish.admin.inc
index 71ff4c0..e780be3 100644
--- a/varnish.admin.inc
+++ b/varnish.admin.inc
@@ -31,14 +31,17 @@ function varnish_admin_settings_form() {
     '#default_value' => variable_get('varnish_flush_cron', 0),
     '#description' => t('Internally Drupal will attempt to flush its page cache every time cron.php runs. This can mean too-frequent cache flushes if you have cron running frequently. NOTE: this cache flush is global!'),
   );
-
-  $form['varnish_legacy'] = array(
-    '#type' => 'checkbox',
-    '#title' => t('Varnish Legacy Mode'),
-    '#default_value' => variable_get('varnish_legacy', 0),
-    '#description' => t('Check this if you use a version of varnish lower than 2.1'),
+  $form['varnish_version'] = array(
+    '#type' => 'select',
+    '#title' => t('Varnish version'),
+    '#default_value' => variable_get('varnish_version', 2.1),
+    '#description' => t('Select your varnish version.'),
+    '#options' => array(
+      '2' => '2.0.x',
+      '2.1' => '2.1.x',
+      '3' => '3.x',
+    ),
   );
-      
   $form['varnish_control_terminal'] = array(
     '#type' => 'textfield',
     '#title' => t('Varnish Control Terminal'),
diff --git a/varnish.module b/varnish.module
index d7e003a..a0d8fa8 100644
--- a/varnish.module
+++ b/varnish.module
@@ -144,7 +144,8 @@ function varnish_expire_cache($paths) {
   $host = _varnish_get_host();
   $base = base_path();
   $purge = implode('$|^'. $base, $paths);
-  _varnish_terminal_run(array('purge req.http.host ~ '. $host .' && req.url ~ "^'. $base . $purge .'$"'));
+  $purge = '^'. $base . $purge .'$';
+  varnish_purge($host, $purge);
 }
 
 /**
@@ -189,7 +190,20 @@ function varnish_flush_caches() {
 function varnish_purge_all_pages() {
   $path = base_path();
   $host = _varnish_get_host();
-  _varnish_terminal_run("purge req.http.host ~ $host && req.url ~ ^$path");
+  varnish_purge($host, $path);
+}
+
+/**
+ * Helper function to purge items for a host that matches the provided pattern.
+ * @param string $host the host to purge.
+ * @param string $pattern the pattern to look for and purge.
+ */
+function varnish_purge($host, $pattern) {
+  // Get the current varnish version, if we are using Varnish 3.x, then we can
+  // need to use ban instead of purge.
+  $version = floatval(variable_get('varnish_version', 2.1));
+  $command = $version >= 3 ? "ban" : "purge";
+  _varnish_terminal_run(array("$command req.http.host ~ $host && req.url ~ \"$pattern\""));
 }
 
 /**
@@ -280,7 +294,7 @@ function _varnish_terminal_run($commands) {
       continue;
     }
     // If there is a CLI banner message (varnish >= 2.1.x), try to read it and move on.
-    if(variable_get('varnish_legacy', 0) != 1) {
+    if(floatval(variable_get('varnish_version', 2.1)) > 2.0) {
       $status = _varnish_read_socket($client);
       // Do we need to authenticate?
       if ($status['code'] == 107) { // Require authentication
diff --git a/varnish.test b/varnish.test
index 99d2060..bc1744d 100644
--- a/varnish.test
+++ b/varnish.test
@@ -17,7 +17,7 @@ class VarnishTestCase extends DrupalWebTestCase {
       $this->varnish_config = array(
         'varnish_control_key' => variable_get('varnish_control_key', ''),
         'varnish_control_terminal' => variable_get('varnish_control_terminal', '127.0.0.1:6082'),
-        'varnish_legacy' => variable_get('varnish_legacy', 0),
+        'varnish_version' => variable_get('varnish_version', 2.1),
         'varnish_socket_timeout' => variable_get('varnish_socket_timeout', VARNISH_DEFAULT_TIMETOUT),
         // We always want this to be set to default.
         'varnish_cache_clear' => VARNISH_DEFAULT_CLEAR,
@@ -362,7 +362,7 @@ class VarnishAdminTestCase extends VarnishTestCase {
     return array(
       'varnish_control_terminal' => variable_get('varnish_control_terminal', '127.0.0.1:6082'),
       'varnish_flush_cron' => variable_get('varnish_flush_cron', 0),
-      'varnish_legacy' => variable_get('varnish_legacy', 0),
+      'varnish_version' => variable_get('varnish_version', 0),
       'varnish_control_key' => variable_get('varnish_control_key', 0),
       'varnish_socket_timeout' => variable_get('varnish_socket_timeout', 100),
       'varnish_cache_clear' => variable_get('varnish_cache_clear', 0),
