Perl expression

I need to calculate the number of pipes '|' coming in my expression.
My expression consists of alphanumeric text including special charactres seperated by colon ':'

W1:W2|W3:W4|W5:W6 .. likewise

I need to calculate number of pipes '|' occuring in them

eg

aaaa : bbbb | cc@34% : ndmmdmd|eeeee:fffff0909|rrr:97892$$$

this contains 3 pipes.

Kindly help with a perl expression

Hi

maybe this:

sed  's/|/\n|/g' file | awk '/^|/{c++}END{print c-1}'

i wrote a one-liner:

perl -e ' my $str = "aaaa : bbbb | cc@34% : ndmmdmd|eeeee:fffff0909|rrr:97892$$$";  while ($str =~ m/\|/g) { $count++; } print $count, "\n";'

hope you get the point.

Can also be done as,

$ echo 'bbbb | cc@34% : ndmmdmd|eeeee:fffff0909|rrr:97892$$$' | perl -a -F'\|' -nle 'print $#F'