#!/usr/bin/perl use v5.14; my $input_line = 'T 1310234540 19<24SomeUserName>19 This is user chat. '; $input_line =~ m/ \< # after the '<' sign, and \d+ # any digits that follow it, (\w+) # capture all letters as $1 \> # then expect the '>' sign \d+\s+ # followed by some other digits and whitespace (.+) # everything that follows is the message /x; my $username = $1; my $message = $2; say "Username: [$username], Message: [$message]";