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