Since I don't have all the commands you're using on my system, here are just some general tips. Your command | fgrep | awk sequences can be rewritten in Perl in the following manner, using xl list as an example. You can write these loops one after the other, first getting the ID, then the VNC port, and finally for the IP address.
use warnings;
use strict;
use IPC::System::Simple qw/capturex/;
my $vm_run = 'zabbix';
my $id;
for ( capturex('xl','list') ) { # loop over lines of command output
chomp; # remove newline
my @F = split; # split the line into fields on whitespace (like a
+wk)
if ( $F[0] eq $vm_run ) { # match on the first field
$id = $F[1]; # store the second field
#last; # would be the equivalent of fgrep -m1
}
}
print "ID: $id\n"; # prints "ID: 2" in this example
Also, I suspect print `$DOMID`; isn't right, you probably don't want to execute the contents of the $DOMID as a command (that's what the backticks will do)? You probably want a simple print "$DOMID\n"; instead.