#!/usr/bin/perl use strict; use warnings; use Data::Dumper; $Data::Dumper::Indent = 1; $/ = q{monkey}; my %hash; while (){ my ($country, $fox_hour) = /forest\s+(\w+).*-fox\s+(\d{4})/s; next unless $country; push @{$hash{$country}}, $fox_hour; } print Dumper \%hash; __DATA__ forest France -wolf -toad -fox 1350 monkey land -dog -cat -slug forest France -deer -swan -fox 1426 monkey forest USA -deer -swan -fox 1560 monkey