in reply to multiple matches with a regex
#!/usr/bin/perl use strict; use Data::Dumper; open FILE, "/tmp/stuff.txt" or die $!; my @contents = split /\n/, do { local $/; <FILE> }; close FILE; my @results = grep { /^here/ } @contents; print Dumper(\@results); __END__ [ contents of /tmp/stuff ] here hereitis hereitwas hereitwillbe thisaintit [ program results ] $VAR1 = [ 'here', 'hereitis', 'hereitwas', 'hereitwillbe' ];
|
|---|