#!/usr/bin/perl -w my $string = "rid"; while (<>) { if (/($string){3}/) { print; } }