in reply to hash components out of order

That's the nature of hashes - in order to give you constant-time access to any element in the hash, regardless of size, the tradeoff is that perl gets to control the ordering of keys. And that order should be somewhat random to provide this ability (look up what "hashing" is in computing science).

What you want is a list. Say an order of operations:

my @datums = ( { field => 'out', snmptag => '1.3.6.1.2.1.2.2.1.16.1', opt => 'U' }, { field => 'in', snmptag => '1.3.6.1.2.1.2.2.1.10.1', opt => 'D' }, # ... # read 'em in (probably don't care about order, but what the heck) for my $datum (@datums) { chomp($data{$datum->{field}} = qx/snmpget -v1 -c $string $ip $datum- +>{snmptag}/) if $opt{$datum->{opt}}; } $update_string = join ':', 'N', map { /: (\d+)/; $1 } @data{ map { $_- +>{field} } @datums };
(untested) I don't really understand what you're doing, so I could have easily misinterpreted some of your code. Note that we probably could get rid of the %data hash, too, and instead just populate a list directly in your order.
my @fields = map { qx/snmpget -v1 -c $string $ip $_->{snmptag}/ =~ /: (\d+)/; $1 } grep { $opt{$_->{opt}} } @datums; $update_string = join ':', 'N', @fields;
Probably a bit easier to read. (and just as tested)