#!/usr/bin/perl $file = "data.txt"; open (INPUT, "< $file"); undef $/; my $string = ; $string =~ s/\n//g; while ($string =~ /A\)(.*?)B\)/g) { print "".$1."\n"; } close (INPUT);