First I would not match against the whole comma separated line, I would narrow the focus to the field that you are interested in. Below I use a split to get field[1]. Another poster suggested using a boundary condition in the regex for the same intended purpose (making sure you are matching against what you think that you are). We don't know what those other names or id's in the line look like, perhaps one server is "sms1Master" or whatever.
Instead of multiple "or" terms, I would use a character set in this case. This makes it easier for me to see what is going to match or not match. Of course mileage varies.
use strict; use warnings; while (<DATA>) { 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
In reply to Re: Case insensitive string comparison
by Marshall
in thread Case insensitive string comparison
by DAN0207
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |