open my $file, 'in.txt' || die "Couldn't open file: $!\n"; #better way to make file handles foreach (<$file>){ #for each line push @matches, $_ if (/abc/); #keep them in an array if they match } print @matches; #print the matches print "Total matches: ",scalar(@matches),"\n"; #print the number of matches