#!/usr/bin/perl open(R, "file.r"); while() { chomp; push @REG,$_; } open(I, "file.i"); while() { chomp; foreach $regex (@REG) { if(/$regex/) { print "$_ matched $regex\n"; for $i (1..5) { if($$i) { print "\t\$$i: $$i\n"; } else { last; } } } } }