while( my $line = . ) { chomp $line; # gets rid of the trailing \n # on second line to allow $ on # the regex below. $line =~ /^(\d{4}-\d{2}-\d{2}).*-{5}\s\S*?\s(\S*)\s(.*)$/; my ( $day, $message, $type ) = ( $1, $2, $3 ); # do what you need to with these }