Yes, you can use that construction. It's known as a "suspended hyphen."
Here is the paragraph on "Suspended hyphens" from the Wikipedia entry on Hyphens
A suspended hyphen (also referred to as a "hanging hyphen" or "dangling hyphen") may be used when a single base word is used with separate, consecutive, hyphenated words which are connected by "and", "or", or "to". For example, nineteenth-century and twentieth-century may be written as nineteenth- and twentieth-century. This usage is now common in English and specifically recommended in some style guides. Although less common, suspended hyphens are also used in English when the base word comes first, such as in "investor-owned and -operated". Usages such as "applied and sociolinguistics" (instead of "applied linguistics and sociolinguistics") are frowned on in English; the Indiana University Style Guide uses this example and says "Do not 'take a shortcut' when the first expression is ordinarily open." (i.e., ordinarily two separate words).
I think as long as you don't make the reader stumble, suspended hyphens are fine. I personally would not use hard- and software because it makes the reader backtrack to fill in "ware" to come up with hardware.