no strict qw/refs/; foreach my $e (qw/a c b/) { if ($$e) { $combined .= $e . "=" . $$e; } } #### foreach my $e ( ["a", $a], ["c", $c], ["b", $b]/) { if ($e->[1]) { $combined .= $e->[0] . "=" . $e->[1]; } }