use strict; use warnings; use IPC::Run3; my @command1 = ('batch1.bat', 'BF1_PARAM1', 'BF1_PARAM2'); my ($in1, $out1, $err1); run3 \@command1, \$in1, \$out1, \$err1; chomp($out1); print "BATCH FILE 1: [$out1]\n"; my @command2 = ('batch2.bat'); my ($in2, $out2, $err2); if ($out1 =~ /batch\s+file\s+output/i) { push(@command2, 'BF2-PARAM1'); push(@command2, 'BF2-PARAM2'); } run3 \@command2, \$in2, \$out2, \$err2; chomp($out2); print "BATCH FILE 2: [$out2]\n"; my @command3 = ('batch3.bat'); my ($in3, $out3, $err3); if ($out2 =~ /batch\s+file\s+output/i) { push(@command3, 'BF3-PARAM1'); push(@command3, 'BF3-PARAM2'); } run3 \@command3, \$in3, \$out3, \$err3; chomp($out3); print "BATCH FILE 3: [$out3]\n"; print "Done\n";