use List::Util qw( shuffle uniq pairkeys ); my @keys = shuffle uniq pairkeys f;