Find Another Guest to Replace You
I was once in a similar situation: I booked a hostel for a week and had to leave after a few days. The hostel basically said they would refund the nights I did not spend there, if and only if they managed to find someone else to replace me. Luckily enough they did, and I got part of my money back.
This is of course a risky move that is not guaranteed to work. However if the hostel has a lot of demand you could be lucky. Moreover, in case of a lengthy booking this could actually work: it might be hard to find someone requesting the exact room/bed you are forfeiting tomorrow. However if you booked for several weeks you are giving the hostel more time to find a new guest.
Another option could be to live it day by day, as others have mentioned in the comments below. I add it here for completeness' sake, even though you explicitly mention it as one you would not consider. You could rent the room/bed on a daily basis, rather than for an extended period, hoping that the hostel you picked will never be fully booked. The main disadvantage here being that in the worst case scenario you might end up changing rooms, or even hostel, every night. I guess flexibility comes at a cost.
One general piece of advice is to cancel the remaining nights within the allowed single-night delay (24h, or whatever) to avoid having to pay for more nights than necessary.
Airbnb is a bit trickier since the money from the reservation is taken from you in advance, meaning that you already paid for the whole stay before arriving.
Flexible and Moderate Policies
If your potential host chose the flexible policy for the reservation, then you can cancel it after arrival, and all nights 24 hours after the cancellation will be refunded at 100%. The moderate policy will instead refund the same nights at 50%.
Work it Out with your Host
If that's not the case, then you could try explaining your situation to your potential host before booking. You might end up working out an agreement. However note that such "agreements" might constitute a violation of the Airbnb Terms and Conditions, since you are not allowed to conduct any form of private trade, after having established contact with the host via Airbnb's website:
You understand and agree that [...] you may not and you agree that you will not:
use the Site, Application, Services or Collective Content to find a Host or Guest and then complete a booking of an Accommodation independent of the Site, Application or Services, in order to circumvent the obligation to pay any Service Fees related to Airbnb’s provision of the Services or for any other reasons;
What about Couchsurfing? Since the relationship between guest and host there is more personal, you could be open with your host and tell them straight away about your situation. Moreover, since no money is involved there everything should be more straightforward.
Why Can't I Book Indefinitely?
I suspect that such open bookings might not be allowed for a number of reasons. For example, some hostels might have limits on the maximum reservation length. Check the top of this FAQ page from Hostel Central:
How long can I stay in a hostel?
Some hostels might have maximum stay restrictions and won’t allow you to stay longer than a couple of weeks, since the idea of hostelling is that people are travelling across a country, and not staying in the same place all the time. However many others will not mind if you stay longer: at the end of the day you are still their customer! As some hostels don’t take residents and locals, you will be required to prove that you are an international traveller by showing you ID or International passport