#!/usr/bin/perl use strict; use warnings; my @array=(); open(my $keyword,'<', "keyword.txt") or die "Couldn't open file file.txt, $!"; open(my $sys,'<', "syslog") or die "Couldn't open file file.txt, $!"; #open($keyword,'>' "keyword.txt") || die "Couldn't open file file.txt, $!"; #open my $keyword, '>' , $file_location3 or die "can't open Keywords:" $!; # gives keywords.txt the file handle keyword and shows #error message if it fails to open #open my $sys, '>' , $file_location2 or die $!; # same as above open(my $fh, '>', 'output.txt'); #my $file_location2 = "syslog"; #my $file_location3 = "keyword.txt"; #arraylisy goes here my $Keyword_or = join '|' , map {chomp;qr/\Q$_\E/} <$keyword>; # lists all lines in indicated file and joins the list in 1 string #regex here removes new line from each line and uses literal regex #which matches even those words with dots my $regex = qr|\b($Keyword_or)\b|; # this regex will match #all the keywords stored in keywords txt file #@array = $Keyword_or; foreach $regex(@array) { #while (/regex/g) #{ #print $NEW "$.: $1"; print $fh $regex; #} #return $keyword; #return $sys; #return $NEW; #print $fh $NEW; close $fh; }