I think that this might need to be `defined $req->{userpic}`?

Also, style nitpick: we prefer as few parentheses and quotes as possible: only when needed for syntax, or clarity. So:

    $msguserpic = $req->{userpic} if defined $req->{userpic};