in reply to find a string and count of its occurence in a text file

As you did, you must open the file, then for every line of file you must check if starts with abc, then you can increment a variable or print out what you need.
open FILE, $file or die "can't open $file: $!\n"; while(<FILE>) { next unless /^abc:/; $counter++; chomp; print "$line\n"; # whatever you need } close FILE;
Doing this way you will never load all the file lines but parse one by one.
as someone noticed grep will work on arrays, so to use it you must load all the lines in one array @array = <FILE> which lead to memory issues if the file is big.

Oha

PS: perl have the poetry of next unless, which is so beauty instead of if(! COND) { continue } I can't avoid posting it! :)