Numbers 31:13-18 NIV

13 Moses, Eleazar the priest and all the leaders of the community went to meet them outside the camp.
14 Moses was angry with the officers of the army1--the commanders of thousands and commanders of hundreds--who returned from the battle.

References for Numbers 31:14

15 "Have you allowed all the women to live?" he asked them.
16 "They were the ones who followed Balaam's advice2 and were the means of turning the Israelites away from the LORD in what happened at Peor,3 so that a plague4 struck the LORD's people.

References for Numbers 31:16

17 Now kill all the boys. And kill every woman who has slept with a man,5

References for Numbers 31:17

18 but save for yourselves every girl who has never slept with a man.