my %hash2 = (); foreach $_ (@array) { $hash2{getkey($_)} = $_ unless /^f/; }