use strict; use warnings; while () { my $SMSfield = (split(',',$_))[1]; if ($SMSfield =~ /SMS[1HI]/i) { print "Match $SMSfield\n"; } else { print "No Match $SMSfield\n"; } } =prints Match SMS1 Match SMSh Match SMSH Match SMSi Match SMSI Match SmsI **Note this match** I think in your case, this is fine. No Match SMSx =cut __DATA__ SMS,SMS1,20190811,084500,servname,servid,servname1,s1,400,300,300,300,300,300 SMS,SMSh,20190811,084500,servname,servid,servname1,s1,700,300,300,300,300,300 SMS,SMSH,20190811,084500,servname,servid,servname1,s1,600,300,300,300,300,300 SMS,SMSi,20190811,084500,servname,servid,servname1,s1,800,300,300,300,300,300 SMS,SMSI,20190811,084500,servname,servid,servname1,s1,500,300,300,300,300,300 SMS,SmsI,20190811,084500,servname,servid,servname1,s1,500,300,300,300,300,300 SMS,SMSx,20190811,084500,servname,servid,servname1,s1,500,300,300,300,300,300