#!/usr/bin/perl -w use strict; my $count = 0; while (<>) { $count += s/foo/bar/g; print; } print "Nothing found!\n" unless $count;