perl -we '$string = qq/9500,9501,fred,,9999/; map { warn qq/Bad entry: $_ in string $string/ } grep ! /^\d{4}$/, split /,/, $string;'