my $input = ; my ($current) = $input =~ /^\s*[\d.]+\s+/ or do { error_stuff(); ... # next, redo, or return, as appropriate }; $input =~ /\s+mA\s*$/ and $current /= 1000;