open my $FH, '>', '3.0_files_arraydata.txt' or die "Cannot open '3.0_files_arraydata.txt' because: $!"; { local @ARGV = <*.xml> or die "Cannot find any '*.xml' files\n"; while ( <> ) { if ( /DATAmessage.*3\.0/ ) { print $FH "$ARGV\n"; close ARGV; } } }