$1 does not contain what you think it does. If you modify your code to wrap your output in a delimiter:
use strict;
my %h = (a1 => 1);
my $test = "a1 to a2";
if ($test =~ /([a-hA-H][1-8]\s*)to(\s*[a-hA-H][1-8])/)
{
print "test work\n";
}
print "x$h{$1}x\n"; #print nothing
print "x$h{a1}x\n"; #print 1
print "x$1x\n"; #print "a1"
you get:
test work
xx
x1x
xa1 x
You are grabbing whitespace in addition to your square id. You'll get your expected result if you modify your regular expression to:
/([a-hA-H][1-8])\s*to\s*([a-hA-H][1-8])/