title: Perl script to parse a text file and match a string
body: <p>I'm editing my question to add more details</p>
  
  <p>The script executes the command and redirects the output to a text file.</p>
  
  <p>The script then parses the text file to match the following string " Standard  1.1.1.1"</p>
  
  <p>The output in the text file is :</p>
  
  <pre><code>             Host Configuration
               ------------------
  
               Profile              Hostname
               --------             ---------
  
               standard             1.1.1.1
               standard             1.1.1.2
  </code></pre>
  
  <p>The code works if i search for either 1.1.1.1 or standard . When i search for standard 1.1.1.1 together the below script fails.</p>
  
  <p>this is the error that i get "Unable to find string: standard 172.25.44.241 at testtest.pl</p>
  
  <pre><code>#!/usr/bin/perl
  use Net::SSH::Expect;     
  use strict;
  use warnings;
  use autodie;
  
  open (HOSTRULES, "&gt;hostrules.txt") || die "could not open output file";
  my $hos = $ssh-&gt;exec(" I typed the command here  ");
  print HOSTRULES ($hos);
  close(HOSTRULES);
  
  sub find_string
  {
  my ($file, $string) = @_;
  open my $fh, '&lt;', $file;
  while (&lt;$fh&gt;) {
      return 1 if /\Q$string/;
  }
  die "Unable to find string: $string";
  }
  
  find_string('hostrules.txt', 'standard 1.1.1.1');
  </code></pre>