# note the three-arg use of open open my $fh, '+>', 'results.txt' or die "Can't open results.txt: $!"; while ( $html =~ /"resumeDetailLink" href="([^"]+)"/sg ){ my $link_url = 'http://www.beyond.com' . $1; print $fh $link_url . "\n"; } close $fh;