my $regex = '(' . join(')|(',@matcharray) . ')'; print "$regex\n"; while(my $line=<>) { chomp $line; print "$line\n" if($line=~/$regex/); }