If you're interested in optimising and don't need a generic solution, then Re^2: Inline C + IO::Handle is going to be fastest. Replace MyFH with whichever namespace the FCGI handle is tied to. Magic is (relatively) slow, and this will avoid it completely.