#! /usr/bin/perl

$n = 0;
$pattern = $ARGV[0]; shift;

while (<>) {
	if (/($pattern)/) {
		$n++;
		s/$pattern/$n/;
	}
	print;
}
