#!/usr/bin/perl -w use strict; use warnings; my $mystring = "ABCblahblahDEF"; if ( $mystring =~ /($.)<\/ID>/) { my $ID = $1; print "$ID\n"; }