#!/usr/bin/perl -w my @code_array = qw(7772344 2233421 TMW2222987 TMA2222333 TMW9999988 AMQ8873332 AMQ1111877); #the 2222987 value will be coming from the db query if ( "@code_array" =~ /(^|\s|[[:alpha:]]{0,3})2222987(\s|$)/ ) { print "Match!! \n"; } else { print "No Match \n"; }