my @codes = qw/ CODE1 CODE2 CODE3 /; my @regex = map { qr/$_/i } @codes; while (my $inputline = ) { my $found = 0; foreach my $regex (@regex) { last if ($found) = $inputline =~ /($regex)/); } next unless $found; # logic goes here }