my %hash; foreach my $key (@list) { foreach ('longstring'.$key.'more') { $hash{$key}{key1} = $_; $hash{$key}{key2} = alter($_); } }