use List::Util 'shuffle'; #### my @friends = map { (split /\./)[1] } ; chomp @friends; #### @friends = shuffle @friends; my %couple = (@friends); #### for (keys %couple) { print "$_ and $couple{$_} are partners\n"; } #### __DATA__ 1.bobby 2.jane 3.charleen 4.markus 5.gabriel 6.Alex