sub is_valid_string { my $string = shift; # Handle the empty case return 0 unless length $string; # Preserve trailing empty fields my @string = split ',', $string, -1; # No commas at the beginning, end, or next to one another. return 0 if grep { !$_ } @string; return 0 if grep { /[^a-zA-Z]/ } @string; return 1; }