#!/usr/bin/perl -w use strict; my @TestInput = ( 'Line One', 'Line Two', 'Line Three', 'Line Four', 'Line Five', ); foreach my $testLine (@TestInput) { print "-----> '$testLine'\n"; if(/(\d\_)+a1/.../(\d\_)+a1/) { my $var3 = "$outdir/$1 +to+ $2.txt"; print " Found '$var3'\n"; } } exit;