# $#array returns the index of the last element of the array. sub queryDBI { my $query1 = "SELECT $_[2],$_[3],$_[$#_] FROM " . $_[1]; return $query1; } print queryDBI(qw/first second third fourth fifth_and_last/),$/ x 2'