http://www.perlmonks.org?node_id=436422


in reply to To Pattern Match or not to Pattern Match

Array elements existence check:
my @all = 1..10; my @some = 1..5; my %h; my @c; @h{@some} = ( ); # Elements that exist in both arrays exists($h{$_}) and push @c, $_ for @all; # @c: 1 2 3 4 5 # Elements that do not exist in @some array exists($h{$_}) or push @c, $_ for @all; # @c: 6 7 8 9 10
Pattern matching negation:
my $string = 'string'; # true: $string =~ /^string$/ and print "$string is really string?\n"; # false: $string !~ /^string$/ and print "$string is not string?\n"; # STDOUT: string is really string