perl -ne 's/\W+/$i++/eg;END{print "$i\n"}' f1 f2