#!/usr/bin/perl -w use strict; my $test = <<"TEST"; Line1 Line3 TEST ; #this worksi - it matches and prints result if ($test =~ m{ \w+\n \n \w+ }msx) { print "Heredoc test: The line \n$test\nmatches.\n"; } open (TEST, "testfile") or die "cannot open testfile testfile - $!"; print "\n==================\nReading testfile\n"; #but this doesn't show a match ... why? while () { if (m{ \w+\n \n \w+ }msx) { print "reading file test: The line \n$_\nmatches.\n"; } } close (TEST); #### Line1$ $ Line3$ #### perl test2.pl Heredoc test: The line Line1 Line3 matches. ================== Reading testfile