#!/usr/bin/perl -w use strict; open my $file,'<', "asdf.txt" or die "Can't open file: $!"; my $text = do { local $/; <$file> }; if ($text =~ /.*(.*<\/somexml>)/s) { print $1; }