IMHO using hashes like this is a bad idea, because different $2 for the same $1 will be lost.
Furthermore looking for non-whitespace and non-punctuation could help practically solving the "what is a word problem".
my %hash;
$whitespace=" \n\t";
$punctuation=".,!?";
$non_delimiters="[^$whitespace$punctuation]";
while (<DATA>) {
push @{$hash{$1}}, $2 while m/($non_delimiters+)\s+going\s+($non_del
+imiters+)/g;
}
use Data::Dumper;
print Dumper \%hash;
__DATA__
I am going home.
I am going to bed.
What's going on?
Output:
$VAR1 = {
'What\'s' => [
'on'
],
'am' => [
'home',
'to'
]
};
I'm still not sure if a hash should be used at all, IMHO an array of pairs (two elemnet arrays) is better.