The line break in your regexp is throwing off your match. If
you make that a single line it ends up getting matches. What
you end up with is a hash where the keys are "Service ..." all
the way to the end of the text block and the values are
"Host: <ip>" strings. So your keys are multi-line blocks of
text and your values are strings that have IP's. That doesn't
seem to be what you'd really want here but maybe it's a start.
You can also put that $/ setting once outside the
loop. I find it good practice to local those but it
doesn't matter much for a standalone piece of code.
I tested this version:
use strict;
use warnings;
my $file = 'input.txt';
my (%hash, @ips, @alerts);
open (FILE, "$file") or die "Can't open $file\n";
local $/ = '-------------------------------------------------';
while (<FILE>){
$hash{$2}{$1} = 0
if (/(Host: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*(Service:.*Sever
+ity:.*)/ms);
}
foreach my $key (keys %hash) {
$hash{$key} = [keys %{$hash{$key}}];
}
my ($key, $values);
while (($key, $values) = each %hash) {
print "$key --> ", join('|', @$values), "\n";
}