#!/usr/bin/perl -w use strict; open , '<', 'textfile.txt'; # a lot of lines later... my $mystring = "ABCblahblahDEF"; if ( $mystring =~ /(.*?)<\/ID>/) { my $ID = $1; print "$ID\n"; # OOOPS.... }