#!/usr/bin/perl -w use strict; my $in_file = 'in.dat'; my $out_file = 'out.dat'; my $spec_text = qr/special text here/; while (1) { open(my $fh_in, '<', $in_file) or die("open failed: $!"); my @lines = <$fh_in>; close($fh_in); if ($lines[$#lines] =~ $spec_text) { open(my $fh_out, '>', $out_file) or die("open failed: $!"); print $fh_out @lines[($#lines - 10) .. $#lines]; close($fh_out); } sleep 60 * 30; # 30 minutes }