foreach my $foo (@foos) { do_more_stuff($foo); if ($foo =~ /baz/i) { next unless $foo eq uc $foo; } else { next unless $foo ne uc $foo; } # stuff }