#!/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; } } } } } #### ^a interface (POS(\S*)) fun #### interface POS5/7 a dog a ant eats stuff. b stuff #### interface POS5/7 matched interface (POS(\S*)) $1: POS5/7 $2: 5/7 a dog matched ^a a matched ^a ant eats stuff. matched ^a