#!/usr/bin/env perl -l use strict; use warnings; my @vars = ('abc,d', 'abcd', 'a,b,c,d'); for my $var (@vars) { print "var = '$var'"; print 'm/,/: ', $var =~ /,/ ? 'not matches' : 'matches'; print 'y/,/,/: ', $var =~ y/,/,/ ? 'not matches' : 'matches'; print '! m/,/: ', $var !~ /,/ ? 'matches' : 'not matches'; print '! y/,/,/: ', $var !~ y/,/,/ ? 'matches' : 'not matches'; } #### var = 'abc,d' m/,/: not matches y/,/,/: not matches ! m/,/: not matches ! y/,/,/: not matches var = 'abcd' m/,/: matches y/,/,/: matches ! m/,/: matches ! y/,/,/: matches var = 'a,b,c,d' m/,/: not matches y/,/,/: not matches ! m/,/: not matches ! y/,/,/: not matches