Code cleaned up and made more Perlish

I went through the code and updated it a bit:

 * Now works with `use strict; use warnings`.
 * Some common patterns (`box`, `prompt`) are abstracted into separate subroutines.
 * Parsing is cleaned up and uses dispatch tables instead of if/else.
 * Perlish idioms employed throughout the code.
 * Small style improvements, e.g. avoiding unnecessary stringification, or using statement modifiers.

The nature of this program made it a bit tricky to test, so it would be good to do a quick test run before merging this pull request – I can't be sure that no regressions were introduced.