Would you like to put parenthesis around the text that you match that you'd like to keep?
$1 will contain the value contained in the first set of parenthesis in the match. $2 will contain the value contained in the second set of parenthesis in the match. And so on.
e.g.
if ( $lastname =~ m/^([\s\w.'-]+)$/ ...
It follows that if there are no parenthesis then $1 will be empty.