for(my $i = 0; $i < count(@{$self->{keys}}); $i++) { my $id = $self->{keys}->[$i]; if($key =~ m!^$id$!) { # do something with the knowledge that we got the correct key # then exit out of function using this loop } } # do something with the knowledge there is no key with that name