  Fragmentation of heavy quarks into heavy-flavoured hadrons receives both
perturbative and non-perturbative contributions. We consider perturbative QCD
corrections to heavy quark production in $e^+e^-$ collisions to
next-to-next-to-leading order accuracy in QCD with
next-to-next-to-leading-logarithmic resummation of quasi-collinear and soft
emissions. We study multiple matching schemes, and multiple regularisations of
the soft resummation, and observe a significant dependence of the perturbative
results on these ingredients, suggesting that NNLO+NNLL perturbative accuracy
may not lead to real gains unless the interface with non-perturbative physics
is properly analysed. We confirm previous evidence that $D^{*+}$ experimental
data from CLEO/BELLE and from LEP are not reconcilable with perturbative
predictions employing standard DGLAP evolution. We extract non-perturbative
contributions from $e^+e^-$ experimental data for both $D$ and $B$ meson
fragmentation. Such contributions can be used to predict heavy-quark
fragmentation in other processes, e.g. DIS and proton-proton collisions.
