use warnings; use strict; my @ports = qw(21 22 23); my $protocol = 'tcp'; for (@ports){ my ($name, $alias, $num, $proto) = getservbyport($_, $protocol); print "$num: $name\n"; }