use strict; my $str='abc%def%.%'; #Get the count by removing all but the percent sign my $pstr=$str; $pstr=~s/[^\%]//sg; my $pcount=length($pstr); print "str: $str\n"; print "pstr: $pstr\n"; print "pcount: $pcount\n";