#!/usr/bin/env perl -l use strict; use warnings; use constant { IP => 0, CMD => 1 }; use Inline::Files; my %data; while () { chomp; my ($host, $ip) = split /,\s+/, $_, 2; $data{$host} = [$ip, []]; } while () { chomp; my ($host, $cmd) = split /,\s+/, $_, 2; push @{$data{$host}[CMD]}, $cmd; } for my $host (sort keys %data) { print "Connect to '$host' at '$data{$host}[IP]'"; print "\tRun command '$_'" for @{$data{$host}[CMD]}; print "Disconnect from '$host' at '$data{$host}[IP]'"; } __IPLIST__ HOST1, 10.10.10.101 HOST2, 10.10.10.102 HOST3, 10.10.10.103 __CMDLIST__ HOST1, CommandA HOST1, CommandB HOST2, CommandC HOST3, CommandD HOST3, CommandE HOST3, CommandF #### Connect to 'HOST1' at '10.10.10.101' Run command 'CommandA' Run command 'CommandB' Disconnect from 'HOST1' at '10.10.10.101' Connect to 'HOST2' at '10.10.10.102' Run command 'CommandC' Disconnect from 'HOST2' at '10.10.10.102' Connect to 'HOST3' at '10.10.10.103' Run command 'CommandD' Run command 'CommandE' Run command 'CommandF' Disconnect from 'HOST3' at '10.10.10.103'