in reply to taint problem

That's because $1 is not defined, since your regexp is not capturing anything; you need parentheses for that. Try this:

if ($lastname =~ /^([\s\w.'-]+)$/ && length($lastname) < 28) +{ $lastname = $1; # $data now untain +ted

the lowliest monk