This snippet grabs the HTTP response and headers of a URL sent in through standard input.
Usage: scriptname URL
Update: As
$code_or_die pointed out, this grabs the full response along with HTTP headers. This is the way I wanted it to work, so I've made this more clear in the title and description.
#!/usr/local/bin/perl -w #turn on warnings
use strict; #always use
use LWP::UserAgent; #used for the request
use HTTP::Request::Common; #used to build request
my ($link,$ua,$req,$results); #declare variables
$link = shift; #grab link from standard input
$ua = LWP::UserAgent->new; #create new user agent
$req = HTTP::Request->new(HEAD => $link);#grab the header
$results = $ua->request($req)->as_string; #grab the results
print "$results"; #print the header info