This is for fixed strings. If you need regexes then replace the @string array with an array of regexes using qr{ } and replace the use of index with an regex call, ala $paragraph =~ $regex[$i].use strict; use warnings; my @string = ('String A', 'String B', 'String C', 'String D', 'String +E'); my @logfile = ('A.log', 'B.log', 'C.log', 'D.log', 'E.log'); my @logfh; open (IN, '<', 'input.txt') or die "Couldn't open input file!\n"; for my $i (0..$#logfile) { open ($logfh[$i], '>', $logfile[$i]) or die "Couldn't create logfi +le!\n"; } local $/ = ''; while (my $paragraph = <IN>) { for my $i (0..$#string) { if ( index($paragraph, $string[$i]) >= 0) { print {$logfh[$i]} $paragraph; } } } close IN; foreach my $fh (@logfh) { close $fh; }
In reply to Re: Parsing log file with blank lines for the field separator
by mscharrer
in thread Parsing log file with blank lines for the field separator
by JasonJ
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |