Consider storing the regexes in an array, and keeping a separate lookup hash for the values ( or using a Tied hash whose key order you can control ). This will let you put the most common cases first, assuming you exit the loop on the first match, and that you are optimizing for speed.