my %hash ={"var1", "info1", "var2", "info2", "var3", "info3"}; my @array=("var1","var2","var3"); my $where = "var1"; my $used = 0; foreach my $item(@array){ if ($item eq $where) { push @result_array, $hash{$item}; $used = 1; } } unless ($used = 1){ push @result_array, $where; } $used = 0;