in reply to Re^4: Loop once on condition 1, many times on cond. 2?
in thread Loop once on condition 1, many times on cond. 2?

You can chain these suckers... so to ensure you do nothing if $x doesn't appear in %my_hash:

foreach $key ( ($x eq 'key_1') ? keys %my_hash : exists $my_hash($x) +? $x : () ) { do a bunch of stuff }
noting that if $x does not exist, what you want is an empty list.