my %inputs = (); for my $index ('input1', 'input2', 'input3') { while ( (my $char = ReadKey 0 ) =~ m/^[0-9]$/ ) { $inputs{$index} .= $char; } }