#!/usr/bin/env perl -l use strict; use warnings; my @acc = qw{AX1 AX2 AX3}; my @sec = qw{PB6 PB7 PB8}; my @third = qw{XC2 XC8 XC1}; my %output_for_option = ( 1 => sub { print "@{get_rand_acc()}" }, 2 => sub { my ($acc, $sec) = (get_rand_acc(), get_rand_sec()); print "@{[ map { $acc->[$_] . $sec->[$_] } 0, 1 ]}"; }, 3 => sub { my ($acc, $third) = (get_rand_acc(), get_rand_third()); print "@{[ map { $acc->[$_] . $third->[$_] } 0, 1 ]}"; }, 4 => sub { my ($acc, $sec, $third) = (get_rand_acc(), get_rand_sec(), get_rand_third()); print "@{[ map { $acc->[$_] . $sec->[$_] . $third->[$_] } 0, 1 ]}"; }, ); while (<>) { chomp; last unless exists $output_for_option{$_}; $output_for_option{$_}->(); } sub get_rand_acc { get_rand_from_array(\@acc) } sub get_rand_sec { get_rand_from_array(\@sec) } sub get_rand_third { get_rand_from_array(\@third) } sub get_rand_from_array { my %h = map { $_ => undef } @{+shift}; return [ (keys %h)[0, 1] ]; }