use strict; use warnings; my $file = 'input.txt'; my (%hash, @ips, @alerts); open (FILE, "$file") or die "Can't open $file\n"; while (){ $/ = '-------------------------------------------------'; $hash{$2}{1} = 0 if (/(Host: \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).* (Service:.*Severity:.*)/ms); } foreach my $key (keys %hash) { $hash{$key} = [keys %{$hash{$key}}]; }