if ($mypattern =~ /$pattern/ig) { ... } elsif ($count eq 0) { ... } else { ... }