in reply to Grouping Multiple Occurences

#! /usr/bin/perl open(FILE,"<pmregex.txt"); my @lines=<FILE>; close(FILE); print "Class ID\n"; my $found=0;my $id; foreach my $line(@lines) { if($line=~ /ID:/) { $id=$'; chomp($id); $found=0; } if($line=~ /Check./) { print "$&"; if($found==0) { print " $id";$found=1; } print "\n"; } }

output
Class ID Check1 001 Check2 Check3 002 Check4
your code seems complex to me so i have written my own
use flag if you want to print a id only once