#!/usr/bin/perl use strict; use warnings; { my %flipflop; sub episode ($$) { my( $start, $end ) = @_; my $id = join( '.', (caller)[0..2] ); ( $flipflop{$id} = 1 ) if $start; my $return = $flipflop{$id} ; ( $flipflop{$id} = 0 ) if $end; return $return; } # episode } for (qw/ ich du er sie es wir ihr sie /) { print "$_ " if episode( /ich/, /er/ ); print "$_ " if episode( /er/, /es/ ); } # for