use Data::Dumper; use strict; # Define actual names (values) for the references (keys) in a hash table my %mapped_vars = ( '1a' => 'One' '2a' => 'Two', '3a' => 'Three', '4a' => 'Four' ); # List of array variables that has to be evaluated. It can also have names that are NOT present in the hash table my @arr_vars = ( '3a','9d', '4a', '7b'); my (@act_vars, $i); my $found=0; # Checking... print Dumper(\%mapped_vars); print Dumper(\@arr_vars); foreach (@arr_vars){ while( (my $key, my $value) = each %mapped_vars){ print "$_-inside while()"; if ($_ eq $key){ push @act_vars, $value; $found =1; #last; } #last LBL; } unless ($found){ print "Inside unless()\n"; push @act_vars, $_; } $found = 0; print "\n"; } print Dumper(\@act_vars);