#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use diagnostics; undef $/; my $file = "test.txt"; open INFILE, "<$file" or die "cant open file: $!\n"; my @arr = ; close INFILE; foreach my $filepieces (@arr) { my @matches = $1 if ($filepieces =~ /alpha\|(.*?)\|/smg); if(@matches) { foreach my $match (@matches) { print "match: $match\n"; } } }