my @lines; open my $fh,'<',$file or die $!; while(<$fh>){   if(/START/ .. /ENDE/){       foo();       push(@lines,$_);   } } close $fh; print $_ for @lines; sub foo {   open my $fh, '<',$otherfile or die $!;   while (<$fh>) {      # operations   }   close $fh; }