while(my $thing = input()){ my $consequence = given_thing($thing,\&get_file,qw(foo bar baz)); ## accept the consequences of your actions ... } sub given_thing { my ($thing,$action,@keys) = @_; do { $thing ~~ $_ and return $action->($thing)} for @keys; }