in reply to matching lines in multi-line string
Don't slurp (well, 'slurp' into an array, not a scalar):
open(FILE, "$filename") or die "Cant open $filename\n"; my @lines = <FILE>; close(FILE); my @patternMatchArray = grep { /$myPattern/ } @lines;
If you don't need all the lines, only the ones that match, you could do it in one shot with:
open(FILE, "$filename") or die "Cant open $filename\n"; my @patternMatchArray = grep { /$myPattern/ } <FILE>; close(FILE);
|
|---|