#!/usr/bin/perl -w use strict; $|++; my $marker = qr/^__END_HEAD__$/; FILE: while( my $file = <*.las> ) { open(FH, $file) or warn "Warning: can't open $file, skipping...\n" and next FILE; LINE: while( chomp() ) { last LINE if /$marker/; # ... } close(FH) or die "ERROR: can't close $file, exiting...\n"; }