$match = '(foo|baz|bar)'; while () { next if ($_ !~ /$match/o); } #### $m_1 = '(bar|baz|foo)'; $m_2 = '([Bb]lah|[Cc]ore)'; $m_3 = '(root|sys|user)'; while () { next if ($_ !~ /$m_1/o); chomp($line = $_); if ($line =~ /$m_2/o && $something) { &func("param"); } elsif ($line =~ /$m_3/o && $something_else) { &other("var"); } }