 <p>To iterate through ENABLE once you have it you should use a simple while loop:</p> <pre><code>while(&lt;ENABLE&gt;){ chomp; //each line read from ENABLE will be stored in $_ per loop } </code></pre> <p>This way you do not need a for loop to iterate. So in essence you would run the "server hostname" command in this while loop:</p> <pre><code>... while(&lt;ENABLE&gt;) { chomp; $ssh-&gt;exec("server $_"); } ... </code></pre> <p><a href="http://perl.about.com/od/perltutorials/a/readwritefiles.htm" rel="nofollow" title="Here">Check here</a> for details.</p>