Software >> Development >> Languages >> Perl >> Regular Expression >> How to count number of leading pipe character

print CountMatch("bc","|") . "\n"; print CountMatch("|bc","|") . "\n"; print CountMatch("|||c","|") . "\n"; print CountMatch("|||||bc","|") . "\n"; sub CountMatch() { $s_string = shift; $count=0; while ($s_string =~ s/^\|//g) { $count++ } return $count; }