my $line = "30.08.2016 08:00:00.004 *ERROR* [pool-7-thread-5] com.day.cq.reporting.impl.snapshots.SnapshotServiceImpl Error accessing repository during creation of report snapshot data\njavax.jcr.LoginException: Cannot derive user name for bundle com.day.cq.cq-reporting [313] and sub service null"; my $pattern = 'ERROR'; my $r = qr/([\d\.]+)\s+([\d:]+)\.?\d*\s+\*(\Q$pattern\E)\*\s+(\[.*?\])\s+([\w\.]+)\s*(.*)/s; my @fields = $line =~ $r; unshift(@fields, undef); # 1-base to match regex capture indexes for my $i (1..$#fields) { print "[$i] '$fields[$i]'\n"; }