Question: In bash, I have the following:

```
#!/bin/bash 
curl $1 | tac | tac | perl -e '/(\d\d(?=:\d\d))/g; print $1' > $2

```

All I want is to the first match from the output of `curl` and print it to the output file. I run the script with `./scriptname url outputfile.txt` but nothing is printed. My regex is valid on <http://regexr.com>, so I'm sure it's something I don't know about Perl. What am I doing wrong? Thanks.

Answer: 
You can use the following:

```
#!/bin/bash
curl "$1" | perl -nle'print for /\d\d(?=:\d\d)/g' > "$2"

```

If you change the match to `/script/g`, you can see it working with something like

```
./scriptname http://www.ucsd.edu outputfile.txt

```
> 
> I suppose this means perl -ne is reading the input line by line. Is there a simple way to have perl return only the first result?
> 
> 
> 

Consider using sed:

```
... | sed '/^.*\([[:digit:]]\{2\}\):[[:digit:]]\{2\}.*/{s//\1/;q};d'

```

In Perl, that would be:

```
... | perl -nle 'if (s/^.*(\d\d):\d\d.*/$1/) { print; exit }'

```

And with GNU Grep compiled with `--perl-regexp`:

```
... | grep -m1 -Po '\d\d(?=:\d\d)'

```