#stop condition is the first empty line. use strict; use warnings; sub mapInEval { my $content = shift; my @lines; my $result; eval { # leaves eval loop, not sub @lines = map { /^$/ ? return : $_ } split /\n/, $content; return 1; }; print "non empty lines: <@lines>\n"; } sub mapNotInEval { my $content = shift; my @lines; my $result; # leaves the sub !!!! @lines = map { /^$/ ? return : $_ } split /\n/, $content; print "non empty lines: <@lines>\n"; } my $spacey = <<__EOF__; Do Re Mi __EOF__ my $notSpacey = <<__EOF__; A B C __EOF__ print "WITH eval { ... } around map\n"; print "testing spacy: "; mapInEval($spacey); print "\ntesting not spacy:"; mapInEval($notSpacey); print "------------------------------\n"; print "WITHOUT eval { ... } around map\n"; print "testing spacy: "; mapNotInEval($spacey); print "\ntesting not spacy:"; mapNotInEval($notSpacey);