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