One simple solution is to not use flash at all, or blend the flash with ambient light. Many answers have addressed these points already so I wont duplicate the advice.
However, flash is often used due to not having enough ambient light, so the above is not always an option.
The problem of bright foreground / dark background exists due to the inverse square law. Simply put light spreads out and loses it's illuminating power quicker and quicker as you move further away. A light at 5 meters has sixteen times the illuminating power as a light at 20 meters.
So what you need to do is place the light in the middle of the scene, so the distances between the light and objects is not as extreme. One way to achieve this is get the flash off camera, off to the side and aim it at the centre of the scene. This however requires an external flashgun and some way of syncing it with the shutter.
Another option is to "bounce" the flash, aim it at the ceiling in the middle of the scene, so that the ceiling becomes effectively a second lightsource that re-radiates light into the scene. This requires a flat ceiling of some neutral colour. Also it helps to have a dedicated flash unit with an pose-able head. However you can get by with a DIY reflector on your on-board flash.