#!/usr/bin/perl use strict; use warnings; open my $new, '<', \<[0]} sort {$a->[1] <=> $b->[1]} map {[$_, /^Conn Culvert Barrel=Culvert(\d+)$/m]} <$new>; #### Connection Culv=This is Line1 - New text here 111 111 This should be new too Conn Culvert Barrel=Culvert1 * Connection Culv=This is Line2 - New text here 222 222 This should be new too Conn Culvert Barrel=Culvert2 * Connection Culv=This is Line3 - New text here 333 333 This should be new too Conn Culvert Barrel=Culvert3 *