for my $file (@files) { open my $fh, '<', $file; select(( select($fh), $~ = "DM", $^ = "DM_TOP" )[0] ); # Data adquisition stuff here write $fh; }