If you want to find all elements in the array that match the pattern, the grep builtin in Perl is your friend.
my @matches = grep { /$stream_s/ } @astreams;
This will try to match each element against the pattern /$stream_s/ and let through only the ones that contain $stream_s. Those end up in your new array.
If you want to reverse this and find all the elements in @astreams that do not match a certain pattern, you just negate the match.
my @not_matched = grep { ! /$stream_s/ } @astreams;
Here's a full example:
use strict;
use warnings;
use Data::Dumper;
my @astreams = qw(
jatm5_INT jatm5_APPL jatm5_JAVA
jatm5_RLS jatm5_EDAG jatm5_REC
5_ASDF
);
my $stream_s = 'jat';
my @not_matched = grep { !/$stream_s/ } @astreams;
print Dumper \@not_matched;
This will output
$VAR1 = [
'5_ASDF'
];
To just do something if any of them doesn't match, but you don't care which one that is, you can use grep inside an if, where its return value will be evaluated in scalar context. That means, the if will look at the number of elements returned by grep. If that is not 0, it is considered a true value and the check passes and the block will be entered.
if ( grep { /$stream_s/ } @astreams ) {
# we found a match, do stuff
} else {
# no match, do something else
}
You can of course also turn that around. All three forms below are equivalent.
if ( ! grep { /$stream_s/ } @astreams ) {
# no match, do something
}
if ( not grep { /$stream_s/ } @astreams ) {
# no match, do something
}
unless ( grep { /$stream_s/ } @astreams ) {
# no match, do something
}
Note that your matching will check if any element in @stream contains (or does not contain) $stream_s.
my $stream_s = 'a';
my @astreams = qw(
jatm5_INT jatm5_APPL jatm5_JAVA
jatm5_RLS jatm5_EDAG jatm5_REC
5_ASDF 5_ASDF_FOOBAR
);
In the above case, the first six elements contain an a somewhere. All of them will match.
my $stream_s = '5_';
my @astreams = qw(
jatm5_INT jatm5_APPL jatm5_JAVA
jatm5_RLS jatm5_EDAG jatm5_REC
5_ASDF 5_ASDF_FOOBAR
);
In this example, all elements contain 5_.
my $stream_s = '5_ASDF';
my @astreams = qw(
jatm5_INT jatm5_APPL jatm5_JAVA
jatm5_RLS jatm5_EDAG jatm5_REC
5_ASDF 5_ASDF_FOOBAR
);
Now the last two will match. If you don't want partial matches, but want to check for exactly that string, don't use a regular expression match.
my $stream_s = 'FOOBAR';
my @astreams = qw(
jatm5_INT jatm5_APPL jatm5_JAVA
jatm5_RLS jatm5_EDAG jatm5_REC
5_ASDF 5_ASDF_FOOBAR
);
unless ( grep { $_ eq $stream_s } @astreams ) {
# only go here if there is no element 'FOOBAR' in @astreams
}
~~. I personally don't like it, but it would have done exactly what you want.