my $dollars = 0; my $pounds = 0; while() { if (/>(\d+\.\d{2})<) { # no dollar sign, must be pounds $pounds = $1 } elsif (/>\$(\d+\.\d{2}) { # it's got a dollar sign, must be a dollar $dollars = $1; } }