my $c; while (<>) { $c += () = /foo/g; } print $c, "\n";