http://www.perlmonks.org?node_id=1214542


in reply to check if string is valid with special cases

If I've understood your specification correctly then this should perform the tests you require.

use strict; use warnings; use Test::More tests => 2; my $valid_in = 'a,b,c,d,e,f'; my $invalid_in = 'a,b,c,d,,f'; ok (test_it ($valid_in), "'$valid_in' is a valid argument"); ok (!test_it ($invalid_in), "'$invalid_in' is an invalid argument"); sub test_it { my ($string) = @_; my @fields = split (/,/, $string); my $emptyfields = grep { $_ eq '' } @fields; if (scalar @fields == 6 && $emptyfields == 0) { return @fields; } return 0; }