for ("a".."c"){ { print && next if /a/; print && next if /b/; # here neither a nor b last; # skip continue-block } continue { # here either a or b print " is in group1"; } print "\n" # all } #### for ("a".."c"){ { if ( /a/ ) { print } elsif ( /b/ ) { print } else { last } print " is in group"; # a,b } print "\n" # all }