in reply to Match a string only once in a file

The obligatory sick version:
my @array = ('file', 'this', 'dog', 'forward'); my %guard; open IN, $Filename or die "$!: $Filename\n"; print join(' ', map { my $line = $_; grep {!exists $guard{$_} and $line =~/$_/ and $guard{$_}=1} @array +; } <IN>), "\n"; close IN;

Caution: Contents may have been coded under pressure.