copied the stuff from T::RL::Gnu's eg/perlsh