#!/usr/bin/perl my $file = '/output.txt'; open DATA, "$file" or die "can't open file"; my @array = ; for($i=1; $i < 10; $i++) { foreach my $found ($array[$i]) { if ( $found =~ /string1/ ) { my @new = join($array[$i], $array[$i++]); } } } close (DATA);