title: Regex not matching if order of items in file changes
body: <p>This is my first attempt at Perl so I know this code is ugly. Some of its from not knowing what I'm doing and some of its from troubleshooting various issues. What I'm trying to do is search a file(samplefile.txt) for various information (the 9 parse_updates functions) and it works fine unless the order changes. For example if one samplefile has Certificate Bundle before Botnet Definitions then it will fail to find the Certificate Bundle information.
  I expected each function to start searching the samplefile &quot;fresh&quot; but that doesn't seem to be the case and I can't figure out why.
  Not including a samplefile as the code post is already long enough and I think the problem is in my function logic.</p>
  <pre><code>
  use strict;
  use warnings;
  use diagnostics;
  use File::Slurp;
  my @autoupdate;
  my $autoupdate;
  
  my $av_regex;
  my @av_updates;
  
  my $avdev_regex;
  my @avdef_updates;
  
  my $ipsatt_regex;
  my @ipsatt_updates;
  
  my $attdef_regex;
  my @attdef_updates;
  
  
  my $ipsmal_regex;
  my @ipsmal_updates;
  
  my $flowav_regex;
  my @flowav_updates;
  
  my $botnet_regex;
  my @botnet_updates;
  
  my $appdef_regex;
  my @appdef_updates;
  
  my $ipgeo_regex;
  my @ipgeo_updates;
  
  my $certbun_regex;
  my @certbun_updates;
  
  my $str1;
  my $str2;
  my $str3;
  my $str4;
  my $str5;
  my $str6;
  my $str7;
  my $str8;
  my $str9;
  
  
   
  parse_updates1(); #AV Engine
  parse_updates2(); #Virus Defs
  parse_updates3(); #IPS Attack Engine
  parse_updates4(); #Attack Defs
  parse_updates5(); #IPS Mal URL DB
  parse_updates6(); #Flow virus Defs
  parse_updates7(); #Botnet Defs
  parse_updates8(); #IP Geo DB
  parse_updates9(); #Cert Bundle
  
  
  sub parse_updates1{
  print &quot;\nTHIS IS AV Engine Section!!\n\n&quot;;
  read_file('samplefile.txt', buf_ref =&gt; \$str1);
  
  
  my $av_regex =qr/(AV Engine)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  if ( $str1 =~ /$av_regex/g ) {
    #putting each regex group into the array
    push @av_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds
    chomp @av_updates;
  
       print &quot;$_\n&quot; for @av_updates;
  
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @av_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @av_updates;
  
  }
  }
  sub parse_updates2{
  read_file('samplefile.txt', buf_ref =&gt; \$str2);
  
  print &quot;\nTHIS IS Virus Definitions Section!!\n\n&quot;;
  
  my $avdef_regex =qr/(Application Definitions)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str2 =~ /$avdef_regex/g ) {
    #putting each regex group into the array
    push @avdef_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @avdef_updates;
   
  print &quot;$_\n&quot; for @avdef_updates;
  
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @avdef_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @avdef_updates;
  
  
  }
  }
  sub parse_updates3{
  read_file('samplefile.txt', buf_ref =&gt; \$str3);
  
   print &quot;\nTHIS IS IPS Attack Engine Section!!\n\n&quot;;
  
  my $ipsatt_regex =qr/(IPS Attack Engine)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str3 =~ /$ipsatt_regex/g ) {
    #putting each regex group into the array
    push @ipsatt_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @ipsatt_updates;
   
  
  print &quot;$_\n&quot; for @ipsatt_updates;
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @ipsatt_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @ipsatt_updates;
  
  }
  }
  sub parse_updates4{
  read_file('samplefile.txt', buf_ref =&gt; \$str4);
  
   print &quot;\nTHIS IS Attack Definitions Section!!\n\n&quot;;
  
  my $attdef_regex =qr/(Attack Definitions)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str4 =~ /$attdef_regex/g ) {
    #putting each regex group into the array
    push @attdef_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @attdef_updates;
   
  
  print &quot;$_\n&quot; for @attdef_updates;
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @attdef_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @attdef_updates;
  
  }
  }
  sub parse_updates5{
  read_file('samplefile.txt', buf_ref =&gt; \$str5);
  
  print &quot;\nTHIS IS IPS Malicious URL Database Section!!\n\n&quot;;
  
  my $ipsmal_regex =qr/(IPS Malicious URL Database)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str5 =~ /$ipsmal_regex/g ) {
    #putting each regex group into the array
    push @ipsmal_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @ipsmal_updates;
   
  
  print &quot;$_\n&quot; for @ipsmal_updates;
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @ipsatt_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @ipsatt_updates;
  
  }
  }
  sub parse_updates6{
  read_file('samplefile.txt', buf_ref =&gt; \$str6);
  
  print &quot;\nTHIS IS Flow-Based Virus Definitions Section!!\n\n&quot;;
  
  my $flowav_regex =qr/(Flow-based Virus Definitions)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str6 =~ /$flowav_regex/g ) {
    #putting each regex group into the array
    push @flowav_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @flowav_updates;
   
  
  print &quot;$_\n&quot; for @flowav_updates;
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @flowav_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @flowav_updates;
  
  }
  }
  sub parse_updates7{
  read_file('samplefile.txt', buf_ref =&gt; \$str7);
  
  print &quot;\nTHIS IS Botnet Definitions Section!!\n\n&quot;;
  
  my $botnet_regex =qr/(Botnet Definitions)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str7 =~ /$botnet_regex/g ) {
    #putting each regex group into the array
    push @botnet_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @botnet_updates;
   
  
  print &quot;$_\n&quot; for @botnet_updates;
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @botnet_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @botnet_updates;
  
  }
  }
  sub parse_updates8{
  read_file('samplefile.txt', buf_ref =&gt; \$str8);
  
  
  print &quot;\nTHIS IS IP geography DB Section!!\n\n&quot;;
  
  my $ipgeo_regex =qr/(IP Geography DB)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str8 =~ /$ipgeo_regex/g ) {
    #putting each regex group into the array
    push @ipgeo_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @ipgeo_updates;
   
  
  print &quot;$_\n&quot; for @ipgeo_updates;
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @ipgeo_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @ipgeo_updates;
  
  }
  }
  sub parse_updates9{
  read_file('samplefile.txt', buf_ref =&gt; \$str9);
  
  
  print &quot;\nTHIS IS Certificate Bundle Section!!\n\n&quot;;
  
  my $certbun_regex =qr/(Certificate Bundle)(.*\n)*?(Version:)(.*\n)*?(Contract Expiry Date:)(.*\n)*?(Last Updated using )(.*\n)*?(Last Update Attempt: )(.*\n)*?(Result: )(.*\n).*/p;
  
  if ( $str9 =~ /$certbun_regex/g ) {
    #putting each regex group into the array
    push @certbun_updates, $1, $2, $3 ,$4, $5, $6, $7, $8, $9, $10, $11, $12;
    #Removing new linefeeds 
    chomp @certbun_updates;
   
  
  print &quot;$_\n&quot; for @certbun_updates;
  }
  else {
    print &quot;\n\nGot Nothing!\n\n&quot;;
    @certbun_updates = qw(notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound notfound);
      print &quot;$_\n&quot; for @certbun_updates;
  
  }
  
  
  # End of sub parse_updates
  }
  
  
  
  
  
  
  
  </code></pre>