http://qs321.pair.com?node_id=689068


in reply to Questions about Grep

If you want to grep a file in Perl, you can read it into an array first:
use strict; open my $fh, "file.txt" or die "Error opening file.txt: $!"; my @lines = <$fh>; my @matches = grep /pattern/, @lines;
There's also the File::Grep module from CPAN which provides some easy-to-use file grepping functionality.