That's not the right approach. See Why it's stupid to `use a variable as a variable name' and A More Direct Explanation of the Problem.
The very fact that @CAT_NEIGH doesn't exist illustrates part of the problem.
Solution:
my @CLASS_TYPES = ("INTRA", "BB", "CAT");
my %NEIGH = (
INTRA => [ "1.1.1.1/32", "2.2.2.2/32" ],
BB => [ "3.3.3.3/32", "4.4.4.4/32" ],
);
for my $class (@CLASS_TYPES) {
next if !$NEIGH{$class};
print "$_\n" for @{ $NEIGH{$class} };
}
or just
my %NEIGH = (
INTRA => [ "1.1.1.1/32", "2.2.2.2/32" ],
BB => [ "3.3.3.3/32", "4.4.4.4/32" ],
);
for my $class (keys(%NEIGH)) {
print "$_\n" for @{ $NEIGH{$class} };
}
@LSP_CLASS_TYPESsupposed to be@CLASS TYPES? It sounds like you really want a hash.