use warnings; use strict; while () { my ($msg, $line) = /((?:(?!\bat\b).)*)(.*)/; print "$msg\n $line\n"; } __DATA__ This is my text at noname2.pl line 4. #### This is my text at noname2.pl line 4.