in reply to if..elseif...syntax problem

It should be elsif, not elseif.

In fact, when I try running this I get an error telling me this very clearly:

elseif should be elsif at ./test.pl line 18.
syntax error at ./test.pl line 20, near ")
               {"
Execution of ./test.pl aborted due to compilation errors.