#!/usr/bin/perl use strict; while () { my $line; ($line) = $_ =~ m|\w+.*\s(http://\w+.*\.html\s)\w+.*|; print "$line\n"; } __DATA__ This is a test this is a test test test http://www.website.com/getme.html this is test this is a test This is a test this is a test test test http://www.website2.com/getme.html this is test this is a test This is a test this is a test test test http://www.website3.com/getme.html this is test this is a test This is a test this is a test test test http://www.website4.com/getme.html this is test this is a test