#!/usr/bin/perl use strict; use FileHandle; # what to watch my %monitor = ( 'messages' => '/var/adm/messages', ); # how to watch it. my %handles; for ( keys %monitor ) { $handles{ monitor{$_} } = new FileHandle "$monitor{$_}", "r" or die "Cant open $monitor{$_}: $!\n"; } # And use it # WARNING blocking code ahead!! my $sentinel; # how we get out of the while 1 while (1) { last if $sentinel; while ( my($file, $fh) = each %handles ) { chomp(my $line = <$fh>); print "Saw in file: $file\n$line\n\n"; $sentinel++ if $line =~ m/somethingorother/; } }