in reply to Hash with sub

Not really sure what you're trying to do... but if the idea is to loop over the keys of either the %dat_mapping or the %eng_mapping hash, depending on whether $hash_name is 'dat', then you could do

#!/usr/bin/perl use strict; use warnings; my %dat_mapping = (foo => 1, bar => 2); my %eng_mapping = (FOO => 3, BAR => 4); my $hash_name = "dat"; for my $file_name (keys %{ $hash_name eq 'dat' ? \%dat_mapping : \%eng_mapping } ) { print "$file_name\n"; }

See Conditional Operator