Mixing colors and patterns is the province of the sophisticated dresser; over-matching -- perhaps best exemplified by those horrible matching tie and pocket square sets -- is a sure sign of a man who doesn't know what he's doing, of someone who looks like he got dressed from a kit.
Maybe the best example of this is an overcoat and felt hat. They should never be the same shade, and ideally shouldn't be the same color. A charcoal coat and hat looks way too matchy; a charcoal coat and medium gray hat looks okay, but is kind of bland. A sophisticated dresser would pair his charcoal coat with a hat of dark brown or navy or midnight blue.
The reverse of this is the two-color rule. Generally, an outfit should have no more than two primary colors, which are the background colors of a suit, shirt and tie (colors in the patterns of such items are accent colors). Also, understand that white doesn't count as a color; it is, by definition, the absence of color.
This rule-of-thumb stems from the fact that the human eye tends to see three or more colors on an item as too "busy" and ugly, while one color usually looks too bland.
(Incidentally, this rule applies to everything, not just clothes.)
Imagine a charcoal suit with a white shirt and a solid charcoal tie. Way too drab. A solid tie in navy or burgundy would look much better.
Now imagine a charcoal suit with a light blue shirt and a burgundy tie. That would tend to look ugly because it contains three colors; it's like the eye has too much to process. It'd be better to change the tie to navy or the shirt to white.
One other element to consider is contrast; it's especially important if you choose to wear one color.
Imagine a solid navy suit with a light blue shirt and a solid navy tie. Drab.
Now imagine the same suit with a white shirt and a navy tie with white pin dots -- this is one of the most elegant combinations possible, even though it's only one color. The difference is the addition of white; while not a color, it adds contrast, especially against dark colors.
This illustrates the point that dressing is an art, not a science; there are always exceptions to rules-of-thumb.
It also illustrates why blending colors and patterns takes sophistication; you have to know when wearing one color -- or three different colors -- works and when it doesn't.
Consider too that the ground of your pocket square counts as one of the two colors, unless it's white. For example, a one-color outfit could be punched up with a burgundy pocket square (in solid or a pattern).
And a really sophisticated dresser might wear burgundy socks with it, adding visual interest where there previously was none.
Also, socks don't count as one of the two colors, because they're only visible when one is seated.
Shoes don't count either; for whatever reason, navy or gray shoes have never connoted much taste, so they'll always be a third color, except when one is wearing a brown suit.
A sophisticated dresser skillfully straddles the line between over-matching and wearing too many background colors at once.