in reply to uninitialized weirdness

Perl is reporting the wrong line numbers. Your elsif conditions are testing the value of $mode, but $mode is uninitialized. Perl is reporting the correct warning, but at the wrong place.