Do you really need to split the paragraph into lines? You can match a multiline string against a regex, too:
#!/usr/bin/perl
use warnings;
use strict;
$/ = "\n\n";
while (<>) {
my @result;
if ( /objectClass:\s+account/
and /objectClass:\s+ifastUser/
and my ($prods) = /ifastProducts:\s+(.+?)\s*$/mg # The /m is
+important here.
and my ($user) = /dn: uid=(\w+?),./g) {
push @result, $prods, $user;
print join '|', @result;
print "\n";
}
}
But if you need the array, you can have it. The , $_) part of your code does nothing, so remove it. Here is my attempt to do what you need:
#!/usr/bin/perl
use warnings;
use strict;
$/ = "\n\n";
while (<>) {
my @result;
my @lines = split /\n/;
if ( ( grep /objectClass:\s+account/, @lines)
and (grep /objectClass:\s+ifastUser/, @lines)
and (my ($prods) = map /ifastProducts:\s+(.+?)\s*$/g, @lines)
and (my ($user) = map /dn: uid=(\w+?),.+/g, @lines
+)) {
push @result, $prods, $user;
print join '|', @result;
print "\n";
}
}