######################### #original account numbers my @code_array = qw(7772344 2233421 TMW2222987 TMA2222333 TMW9999988 AMQ8873332 AMQ1111877); #account numbers in @code_array has been processed and the letters before any account has been removed, so I have this: my @code_array_noletter = qw(7772344 2233421 2222987 2222333 9999988 8873332 1111877); my $plc_holders = join ( ',', ('?') x @code_array_noletter ); #this table is numeric, letters has been removed from account numbers my $databasse_cheks="SELECT accounts, id FROM accountstable WHERE accounts IN ($p_holders_state)"; # assuming all db stuff like connection,prepare,execute has been done at this point while (my $pt = $sth->fetchrow_hashref) { my $accountnumber = $pt->{'accounts'}; my $acc_id = $pt->{'id'}; #matching account numbers in @code_array at the numeric level, with what was found in the DB::: if ( "@code_array" =~ /(^|\s|[[:alpha:]]{0,3})$accountnumber(\s|$)/ ) { # in here I need to store the acc_id the match what was found in the @code_array. # matching on these account numbers as an example, 7772344 2233421 TMW2222987 i have to attache # the acc_id to it. And that's my problem. # I think it has to be done using a hash but having problems trying. # results before storing in a hash or some other way, will be the account number and its id: # 7772344 34 2233421 54 TMW2222987 66 # need to push all this here to get access out side of the while } #print here for testing the results:::: #########################