if ($largestring =~ /Total Cost: (\d+)/) { $x = $1; } else { $x = 0; }