foreach my $i ( $from .. $to ) { next if ($i % 2 || $i % 3 || $i % 4 || $i % 5); say $i; }