#!/usr/bin/perl -w use strict; my @saves; # we will save our stuff in here my @ok_posters = qw ( Administrator Sam ); # generate a regex to match our approved posters my $ok_regex = join "|", @ok_posters; my $ok_regex = qr/(?:$ok_regex)/; { # use local to localise the change to the input record # separator to this block only, saves nasty suprises local $/ ="_________________________________________________________\n"; # read in data from file handle one record at a time # each record is stored in the magical $_ var while () { # add data to our array if it matches # the required criteria push @saves, $_ if /^From\s+$ok_regex/; } } print @saves; # this is how you read from the file message.txt instead of #{ # local $/ ="_________________________________________________________\n"; # open (FILE, ") { # push @saves, $_ if /^From\s+$ok_regex/; # } # close FILE; #} # uncomment this to save the results # save("c:/mysaves.txt", @saves); sub save { my $file = shift @_; my @stuff = @_; open (FILE, ">$file") or die "Unable to open file for writing, Perl says: $!\n"; print FILE @stuff; close FILE } __DATA__ From Sam (Wed Jul 11 18:12:08 2001): This space intentionally filled. _________________________________________________________ From Administrator (Wed Jul 10 01:05:55): Message _________________________________________________________ From Sam (Wed Jul 11 18:12:08 2001): This space intentionally filled. _________________________________________________________ From Blah Blah (Wed Jul 10 01:05:55): Message _________________________________________________________ From Sam (Wed Jul 11 18:12:08 2001): This space intentionally filled. _________________________________________________________ From Blah Blah (Wed Jul 10 01:05:55): Message _________________________________________________________