#!/usr/bin/perl -w use warnings; use strict; my $var = "abc,d"; if($var =~ /,/) { print "not matches \n"; } elsif($var =~ /(.*)/) { print "matches \n Captured: $1\n"; } $var = "abcd"; if($var =~ /,/) { print "not matches \n"; } elsif($var =~ /(.*)/) { print "matches \n Captured: $1\n"; } exit 0; #### not matches matches Captured: abcd