Since your loops are nested, you move through the entirety of file2 before you go to the second line of file1. Perhaps you mean something more like (untested):

print HDLCGET "\#\!\/usr\/local\/bin\/expect\n"; print HDLCGET "set timeout -1\n"; open(MYINPUTFILE, "<", "hdlc2") or die "Open MYINPUTFILE failed: $!"; open(MYINPUTFILE1, "<", "hdlc3") or die "Open MYINPUTFILE1 failed: $!" +; while(<MYINPUTFILE>) { my($line) = $_; chomp($line); #my($line1) = <MYINPUTFILE1>; # This slurps the file - oops my $line1 = <MYINPUTFILE1>; chomp($line1); print HDLCGET "spawn \ ssh $line\n"; print HDLCGET "expect \"assword: \"\n"; print HDLCGET "send \"$tacacspw\\r\"\n"; print HDLCGET "expect \"#\"\n"; print HDLCGET "send \"terminal length 0\\r\"\n"; print HDLCGET "expect \"#\"\n"; print HDLCGET "send \"show xconnect all | inc $line1\\r\"\nexpect +\"#\"\n"; print HDLCGET "send \"exit\\r\"\n"; print HDLCGET "interact\n"; } close(MYINPUTFILE); close(MYINPUTFILE1);

Note also I swapped to the three-argument form of open and added a test to make sure the open succeeded - part of the same advice toolic gave you in Re: using multiple input files. Also, you might read How do I post a question effectively?, as debugging file-processing code w/o the files to be processed can be tricky.

Update: As discussed below, the above code was buggy. Corrected the error and kept the original line as a comment for posterity.


In reply to Re: Using multiple input files #2 by kennethk
in thread Using multiple input files #2 by ddrew78

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.