$num = random(1,5,1);
$alt1 = "\(E_i = h^$num\)";
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 see
http://webwork.maa.org/wiki/Basic_Perl_syntaxparticularly 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.