show_these($hash_ref,[ field3, field2, field1 ]); sub show_these { my ($dr,$show) = @_; my $output; for my $row (keys %{$dr}) { for (@{$show}) { next if !$dr->{$row}{$_}; $output .= qq!$_ = $dr->{$row}{$_} !; } $output .= "\n"; } return $output; }