my %xmlstring = ( QueryCId => qr/]*>\s*(\d+)\s*<\/nC[o]?ntr[a]?ctID>/s, ); print "\nreg: ", $nsi[$index] =~ /$xmlstring{'QueryCId'}/; $nsi[$index] =~ /$xmlstring{'QueryCId'}/ ? print "\nMATCH" : print "\nNO MATCH"; $nsi[$index] =~ /$xmlstring{'QueryCId'}/ ? $cid = '' : $cid = 'I HATE YOU'; print "\nCID should be empty: ", $cid;