$num = random(1,5,1); $alt1 = "";
Any dollar sign variable inside double quotes in perl is replaced by its value. Single quotes prevent variable interpolation. For a very quick start on perl seehttp://webwork.maa.org/wiki/Basic_Perl_syntax
particularly the section on quotes.
For more details see the links on that page and for a book I highly recommend "Learning Perl" by Randal Schwartz and Tom Phoenix.