RECORD 1 ###### Full Name 1a Street Address 1a City 1a ST1a Zip_1a COUNTY 1a 0######## Full Name 1b abcABCabc 99/99/9999 Street Address 1b City 1b ST1b Zip_1b COUNTY 1b RECORD 2 ############ Full Name 2a 99/99/9999 Street Address 2a City 2a ST2a Zip_2a COUNTY 2a 0### Full Name 2b abcABCabc 99/99/9999 Street Address 2b City 2b ST2b Zip_2b COUNTY 2b #### if ($array[$line] =~ /0?.*?(RECORD .*)/){ $record = trim($1); # works correctly $array[$line+1] =~ /(\d+)(.*)/; $id = trim($1); # works correctly $name = trim($2); # works correctly # still looking at the "a" lines, sometimes there's a date, sometimes no date $array[$line+2] =~ /.*?(\d{2}\/\d{2}\/\d{4})?(.*)/; $date = trim($1); # when no date it's using the previous $1 that goes into $id $address = trim($2); # when no date it's using the previous $2 that goes into $name ... code continues ...