#!/usr/bin/perl use strict; use warnings; while () { my $one = $1 if /^\{\w+\s+\d+\}([^\s\t]+)/; my $two = $1 if /^\{\w+\s+\d+\}\s+(.*)/; print "ONE: $one\n"; print "TWO: $two\n"; } __DATA__ {STRING 4} 123.122.124.125 some text here #### ONE: {STRING 4} TWO: 123.122.124.125 some text here