my %format = ( $x => "... for x", $y => "... for y" ); my $val = ( $EXPR ) ? $x : $y; my $var = sprintf( $format{$val}, $val );