my $comment = '^(\/\*.*\*\/\;)(.*)'; [...] while ($statement !~ m{$comment}s) { $statement .= <$file> or die "Premature EOF.\n"; } print "Found type 1 comment: $1\n";