my $start = 'string-here string-here:'; my $level = '\((\w+)\)'; my $group = '([\w\s]+) completed,'; my $total = 'Total (\d+) client\(s\),'; # if there are details, they're captured in the end parens my $re = qr/^$start $level $group $total ?(.*)$/;