use List::Util qw(first); for my $n (0 .. 267) { print "$n\n" if first {$n == $_} 40, 47, 76; }