my $a = 1; my $b = 2; my $c = 3; my $combined = join ' ', map { "$_->[0]=$_->[1]" } grep { $_->[1] } map { [ $_, eval('$'.$_) ] } qw(a b c);