foreach my $i (grep {/^name\d+$/} keys %in) { print "$i: $in{$i}\n"; }