The E34 540i was available in 1994 and 1995. These cars typically sell for $5-25k, depending upon specification (automatics are worth less, M-Sport limited edition 6spd are worth the most) and mileage. The 4.0 liter V8 has problems, and should be avoided unless it has had the nikasil-lined block replaced with an alumasil one. The auto trannies don't last that long, but that is typical for BMWs (and I hope you are getting a 6spd). (Hence $5k for a 540ia with a nikasil engine, and auto tranny if both are failing)
Great cars, but they are getting expensive to run.
An E34 M5 is a wonderful, hand-built M-car, but not really a good choice for a daily driver. If you live in a warm climate and don't have to commute through rush hour traffic, it might not be a bad choice. It will cost in maintenance, and many have been run fairly hard.
In the US, you have 1991-1993 E34 M5s. I think they imported around 2000. You really should familiarize yourself with
www.m5board.com
Later 3.8 liter cars (93-95) were not for US sale. Some have been imported, and perhaps 3-5 are available at any given time, for $25-35k.
The E39 is probably what you want. 1997-2003.
I would look for a 2001 540i. A good CPO car with a few years and 40-50k left on the warranty should run $35k or less. 1997s with 60k miles are in the high teens to low 20s.
I came within inches of buying a 2001, but ended up with a FWD TL for the Wisconsin winter.
I hope to have an M5 in a few years.