diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb
index 1ccbacb4ab789be2a12817d8416d73edb56ad468..9299d62996e3254ca9fd2f95c7d1f4febd58f322 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -58,10 +58,17 @@ class Keg <Pathname
     link_dir('etc') {:mkpath}
     link_dir('bin') {:skip}
     link_dir('sbin') {:link}
-    link_dir('lib') {|path| :mkpath if %w[pkgconfig php perl5 perl5/site_perl].include? path.to_s}
     link_dir('include') {:link}
     link_dir('share') {|path| :mkpath if mkpaths.include? path.to_s}
 
+    link_dir('lib') do |path|
+      case path.to_s
+      when /^pkgconfig/ then :mkpath
+      when /^php/ then :mkpath
+      when /^perl5/ then :mkpath
+      end
+    end
+
     return $n+$d
   end