diff --git a/Library/Homebrew/os/mac/xquartz.rb b/Library/Homebrew/os/mac/xquartz.rb
index b7ecd856ad5cd3731c06dc71f0410b35ce1ae521..a836abcbc8fe9bf37a2585b2c48881fb68a3ccc2 100644
--- a/Library/Homebrew/os/mac/xquartz.rb
+++ b/Library/Homebrew/os/mac/xquartz.rb
@@ -24,7 +24,7 @@ module MacOS::XQuartz extend self
       else
         # Finally, try to find it via pkgutil. This is slow, and only works
         # for the upstream XQuartz package, so use it as a last resort.
-        MacOS.pkgutil_info(FORGE_PKG_ID) =~ /version: (\d\.\d\.\d).+$/ and $1
+        MacOS.pkgutil_info(FORGE_PKG_ID)[/version: (\d\.\d\.\d).+$/, 1]
       end
     end
   end