in reply to Search for abcNUMBERdef, make it a variable, then do math?

Every regex starts an new sequence of $1, $2, $3, ... again. Therefore each of your captures goes into the same $1. You do capture all the numbers, but overwrite them with the capture of the next regex and therefore it ends up with the last capture in $1 and all other still zero (in numeric context).

As a best practice, you should waste no time or processor cycles before you put the results of the captures stored in $1 and its brethren into regular variables. Never ever trust them to "keep" their values. A subroutine far far away in another module my decide at any moment to trash them for its own use.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Search for abcNUMBERdef, make it a variable, then do math?
by AnomalousMonk (Archbishop) on Jan 22, 2011 at 09:16 UTC
    $id4 =~ /yesterday(\d+)yesterday/; my $ans2 = $2 * .40; $final2 = ($ans2 / 100);

    Jesse Smith: Further to CountZero's reply: in the above quoted and in subsequent steps in the OPed code, the capture variable  $2 (and subsequently  $3 $4) is used in a calculation, but there is no second (or third or fourth) capture group to populate this variable with a defined value. The fact it is undefined would have been made evident to you had you been using warnings (and strictures for good measure – and diagnostics for even better measure since you are learning Perl):

    use warnings; use strict; use diagnostics;

    See perlre, perlrequick, perlretut, perlreref for regular expression (re) on-line documentation, or  perldoc perlre etc for local installation documentation.