Fragmentation of nanowires driven by Rayleigh instability