my @emails = split(/\s*,\s*/, $email); if (@emails > 3) { ... warn ... } # Keep only the first three. splice(@emails, 3);