sub test { my ( $s ) = @_; if ($s == 3) { no warnings 'exiting'; # suppress the warning for this lexical scope only. next; } else { print $s . "\n"; } }