my @keys = ("Update Time", qw/Targets Complete Waiting/); my %hash; # fill in %hash (method not clear from OP) print join ',', @hash{ @keys }; # or use e.g. Text::CSV_XS