in reply to errors

Not sure why your code is breaking but perhaps a better way to do that while loop (rather than scalar assignments on $_ would be the following:
perl -e "while (<>) { last if m/^quit$/ }"

Celebrate Intellectual Diversity