It's too hard to get compatibility between GNU and BSD sed, so let's just use perl oneliners. And improve it to also remove trailing tabs, not just spaces.