in reply to Best way to implement ungetstring?

Probably best done as a PerlIO layer. See man PerlIO and man PerlIO::via.

Abigail