#!/usr/bin/perl -w use strict; open (INPUT,"file") or die "Unable to open input : $!"; open (OUTPUT,">output") or die "Unable to open outpu : $!"; select OUTPUT; $\ = "\n"; my $foundstart; while () { chomp; next unless ($foundstart || //i); if (//i && ! $foundstart) { $_ =~ s/^.*?(.*)$/$1/i; $foundstart++; next unless($_); } if ($_ =~ m||i) { $_ =~ s|^(.*?).*$|$1|i; print if($_); last; } print; } close INPUT; close OUTPUT;