# Figure out what actions the user wants to monitor. my $monitored_actions = join "|", @ARGV; # Create a monitoring RE that can be used again and again # without re-compiling it. my $monitor = qr/$monitored_actions/; { # Decide what action to take. my $action = ('ADD', 'REMOVE', 'DELETE', 'QUIT')[rand(3)]; # And here we monitor it. $action =~ /$monitor/ && do { print $action, "\n"; }; redo unless $action eq 'QUIT'; } #### ./mytest ADD REMOVE