#!/usr/bin/perl use strict; use warnings; my $file = 'test.dat'; open(my $fh,"<$file") or die $!; while(<$fh>){ if(/#vermerk/.../^$/){ print unless(/#vermerk/ || /^$/); } } close $fh;