use warnings; use strict; use feature 'say'; use Var::Pairs; my %hash; @hash{"a".."d"} =1..4; sub till { my $goal = shift; while (my $next = each_pair %hash) { say $next->key, ' had the value ', $next->value; last if $next->key eq $goal; } say "-"x10 . "exit"; } till("a"); till("a"); till("a"); till("a");