open TESTFILE, "Y:/Perl Projects/TEST" or die "Couldn't open Test Report file: $!"; my ($variable1, $variable2); my @return_details, while (my $test = ) { #if i delcare the variable here it will re-inialize it next time it loops through to an undef. next if ($returns =~ m/^(\s)*$/); print $returns; if (substr($test , 80, 26) =~ m/1ST VARIABLE/) { $variable1 = substr($returns, 113, 18); next; }; if (substr($test , 80, 25) =~ m/2ND VARIABLE/) { $variable2 = substr($test, 113, 18); $rt_flg = 1; }; if ($rt_flg eq 1) { push @return_details, { variable1 => $variable1, variable2 => $variable2 }; $rt_flg = 0; }; };