{ my $state = 'start'; my $crit = 3; sub f_ab { my ($value) = @_; my $return = 0; if ($value >= $crit and $state ne 'high') { $state = 'high; } elsif ($value < $crit and $state ne 'low') { if ($state eq 'high) { $return = 1; } $state = 'low'; } retrun $return; } }