while (my $line = ) { next unless $line =~ /^\~\|TOTAL/; my @percents = ( $line =~ /([\d\.]+)/g ); .. do something with @percents .. }