use feature 'state'; sub foo { state $i++; $i=shift()-1 if @_; return $i; } foo 1; print foo."\n" for 0..9; foo 0; print foo."\n" for 1..5;