sub add{ shift(@_) + (@_? add(@_):0) } #Test the "add" routine .. print add(qw/3 0 0 1 0 1 01 1 1 1 1 0 1 /); # Outputs : # 11