my $foo = split (/,/, $bar); #### my $foo = ($bar =~ /,/) + 1; #### my $foo = defined($bar) && length($bar) && (($bar =~ /,/) + 1);