in reply to modification of simple form-email script

The problem may lie in the if statement it self.
if ($name = "firstname"){
isn't checking anything it is assigning someting. You want
if ($name eq "firstname"){
'=' assigns '==' is numerical comparisons and 'eq' is for string comparisons. (by design not by force)

If you did this with CGI you could do this:
use CGI; use strict; my %FORM; map {$FORM{$_} = uri_unescape($cgi->param("$_"))} $cgi->param(); if ($FORM{firstname} eq '') { die print "must enter first name"; }
or something along those lines, but you shouldn't die in CGI either. There are much more graceful and correct ways to handle it. So a super search for CGI Ovid and you should find loads of helpful information.