local $/ = undef; my $whole_file = <>; # slurp while ( $whole_file =~ /^(.*)$/mg ) { # process line by line print "Got: $1\n"; }