use strict; my $word = ; if($word=~/(.*)(.*c)((.*w){2,3})(.*)/){ print length($2)+length($3),"\n"; }else{ print -1,"\n"; }