#!/usr/bin/perl -w use strict; my $a = "first"; makejoin( 'second', 'third'); makejoin( undef, 'third'); makejoin('second', undef); sub makejoin { my ($b, $c) = (@_); my $join = " where "; $join .= defined ($b) ? $b . (defined($c) ? " and $c " : '') : $c; print $a, $join, "\n"; }