sub array_to_string { my ($array, $switch) = @_; $switch = '-' if $#_ < 1; join $switch, @$array; } array_to_string([1..3], '#'); #array_to_string([1..3]);