The quick-and-dirty way is:
perl -nE 'say $1 if /myserver1\s+(\w+)$/' path/to/hostfile
You might need to do queries similar to this from time to time, so you could probably make a reusable chunk of code to do this for you. Something like:
#!/usr/bin/perl
use strict;
use warnings;
use 5.10;
use HostFileParser;
my $host = HostFileParser->parse("path/to/hostfile")
my $server = $host->find(server => "myserver1")
say $server->alias;
Of course, I'm not going to "give you teh codez" for all of that. ;)
(These answers assume Perl 5.10, but if you don't have it the changes are just say $x
=> print "$x\n"
, or sub say { print "@_\n" }
.)