use List::MapMulti qw(mapm); my @keys = sort keys %hash; mapm { my ($QB1, $QB2, $RB1, $RB2) = @_; ...; } (\@keys) x 4;