in reply to Issue with regex matching

Alternatively, you could avoid the troubles with a regular expression by setting the record separator $/ to the expression you look for. When you read the file into an array, you get one more elements than the occurences of the string you are looking for:

use strict; use warnings; my $constant = '$$'; my $count = -1; { local $/ = $constant; $count += () = <DATA>; } print "$count\n"; __DATA__ $$ ss $$ ss $$ ss ss

(UPDATE) or as a one-liner:

my $count = do { local $/ = $constant; () = <DATA> } - 1;