#!perl use strict; use warnings; my @preferred = qw(best good normal bad worst); my @routers = qw (asda adsas asdasds); foreach my $router(@routers){ my $best_of = best_of($router); } sub best_of { my $router = shift; my %available; @available{get_available($router)};# get_available return a list # used as keys of %available hash # for our comfort map { return $_ if exists %avalable{$_} } @preferred; }