foreach (@SQL_queries) { my $Results = $_; my $sth_atl = $dbh->prepare($Results) or die "Couldn't prepare query: ".$dbh->errstr; $sth_atl->execute() or die "Couldn't execute query: ".$sth_atl->errstr; my $cols_for_row; while ($cols_for_row = $sth_atl->fetchrow_arrayref) { print OUTFILE "England\t"; print OUTFILE join("\t",@$cols_for_row),"\n"; my $last_element = @$cols_for_row[-1]; my $indicator = @$cols_for_row[-2]; my $numerator; my $denominator; if ($indicator eq "SH"){ $numerator = $last_element; } elsif ($indicator eq "SL"){ $denominator = $last_element; } else { print "\nError: There has been an unexpected string within the second to last element of the array\n"; } print "\n>>>>>numerator>>>>>>>>>>>> $numerator\n"; # Works here print "\n>>>>>>denominator>>>>>>>>>>> $denominator\n"; # Works here if (($numerator > 0) && ($denominator > 0)){ print "\n>>>>>numerator>>>>>>>>>>>> $numerator\n"; # Does not work here print "\n>>>>>>denominator>>>>>>>>>>> $denominator\n"; # Does not work here my $expected_ratio_figure = ($numerator)/($denominator); print OUTFILE "\n\nThe expected ratio figure:\t"; print OUTFILE "$expected_ratio_figure\n\n"; } } }