my $bigpattern = '(' . join('|',@patterns) . ')'; while (my $inputline = ) { if ($inputline =~ /$bigpattern/io) { ## Logic goes here } }