##!/usr/bin/perl -w use strict; use warnings; open (FILE,"< C:/perl/ParentChildTreeFile.txt") or die "cannot open file for reading: $!"; while (){ if ($_ = /^(IPR\d+).*/){ my $parent = $1; print "\n Parent is $1"; } elsif ($_ = /^--(IPR\d+).*/){ my $firstchild = $1; print "\n $parent First generation child is $firstchild"; } elsif ($_ = /^----(IPR\d+).*/){ my $secondchild = $1; print "\n $parent Second generation child is $secondchild"; } }