A machine of this type, of great antiquity and fine pedigree, is Maxwell's Demon, the prodigy of James Clerk Maxwell, one of the biggest brains in nineteenth century science and the architect of the modern classical theory of electricity and magnetism.
Maxwell's Demon is a simple beast: he sits at the door of your office in summertime and watches the molecules wandering back and forth. Those which move faster than some limit he only lets pass out of the room, and those moving slower than some limit he only lets pass into the room. He doesn't need to expend energy to do this -- he simply closes a lightweight shutter whenever he spots a molecule coming that he wants to deflect. The molecule then just bounces off the shutter and returns the way it came. All he needs, it would appear, is patience, remarkably good eyesight and speedly reflexes, and the brains to figure out how to herd brainless molecules.
The result of the Demon's work is cool, literally. Since the average speed at which the molecules in the air zoom around is what we perceive as the temperature of the air, the Demon will by excluding high-speed molecules from the room and admitting only low-speed molecules cause the average speed and hence temperature to drop. He is an air-conditioner that needs no power supply.
Alas, Maxwell's Demon is an impossible beast. He violates The Second Law, because the net effect of his manipulations is to transfer energy from inside the room to outside the room with no waste whatsoever. Oh well. If you would like a detailed exorcism of the Demon, the best is contained in Science and Information Theory (Academic Press, New York, 1956) in a beautiful article by Leon Brillouin, a giant of twentieth century physics. The essence of the refutation is that the Demon cannot see the molecules unless he uses a flashlight, and thus spends energy. Since the crux of the matter is the information the Demon must possess, you may see why the article is contained in a book on "Information Theory". And indeed it turns out there are deep connections between the Second Law and information theory -- the science of knowing when you know.
A more modern version of the Demon is this: consider a diode rectifier, a device which you are told in elementary electronics class passes electrical current (the motion of electrons) in only one direction. In such a device it would appear that the random bumping around of electrons (that's a form of heat) would lead to a net flow of electrons in the allowed direction, as electrons that bumped into the diode junction going the wrong way would bounce back, and the those going the right way would pass through. This is just like Maxwell's Demon using the random motion of the molecules to achieve a net flow of fast molecules.
Hey, but a net flow of electrons through the diode is an electrical current! You can apparently generate a macroscopic flow of energy (a current) out of nothing but pure heat. (This is like the random jiggling motions of the box conspiring to reform the bouncing motion.) We could gang six million of these widgets together and dump them into the Pacific Ocean, a practically inexhaustible source of heat, and apparently generate electrical power forever for free.
Don't buy stock yet. It's another Demon, and another fraud.
There are many perpetual motion machines of the second kind, each more fiendish and subtlely flawed than the last. Luckily for the Patent Office The Second Law simply forbids each and every one.
Incidentally, a perpetual motion machine of the first kind is one which violates The First Law, by creating energy out of thin air. These are a little easier to spot -- if I claim to turn my airplane propeller with a rubber band and to wind the rubber band with a windmill mounted on the airplane wings, most folks even without the benefit of a course in thermodynamics would decline my offer of a free ride right away.